UpNext

10.9.1  Overview

Mythryl is a (mostly-)functional programming language; functions are accordingly of central importance.

From a strictly formal point of view, every Mythryl function has exactly one argument and returns exactly one result, which is to say it has type

    Input_Type -> Output_Type;

Thus, the canonical Mythryl function is something like

    linux$ cat my-script
    #!/usr/bin/mythryl

    fun reverse_string string
        =
        implode (reverse (explode string));

    printf "reverse_string \"abc\" = \"%s\".\n" (reverse_string "abc");

    linux$ ./my-script
    reverse_string "abc" = "cba".

We frequently think of Mythryl functions as taking multiple arguments because the input type is often a tuple or record:

    linux$ cat my-script
    #!/usr/bin/mythryl

    fun add_three_ints (i, j, k)
        =
        i + j + k;

    printf "Result = %d\n" (add_three_ints (1, 2, 3));

    linux$ ./my-script
    Result = 6

From a formal point of view, however, this is still a function taking a single argument, which is then pattern-matched into its constituent elements. This is more than a theoretical fiction. For example, we can compute the argument tuple separately and then provide it to the function as a single argument:

    linux$ cat my-script
    #!/usr/bin/mythryl

    fun add_three_ints (i, j, k)
        =
        i + j + k;

    arg = (1, 2, 3);

    printf "Result = %d\n" (add_three_ints arg);

    linux$ ./my-script
    Result = 6

Comments and suggestions to: bugs@mythryl.org

UpNext