PreviousUpNext

10.9.3  Anonymous Functions

Mythryl makes it easy to write anonymous functions. The basic syntax is:

    
arg = expression

Such functions are typically passed as arguments to other functions:

    linux$ my

    eval: map  (\\ string = implode (reverse (explode string)))  [ "abc", "def", "ghi" ];

    ["cba", "fed", "ihg"]

Like named functions, Mythryl anonymous functions support implicit case statements. The general syntax is

    
pattern => expression;
     pattern => expression;
     pattern => expression;
     ...
    end

Arbitrary pattern-matching may be done, but ordinarily if you are going to write many cases with complex patterns and expressions, you will probably just make it a named function.

Here is a simple example of using this facility to special-case empty strings:

    linux$ my

    eval: map  \\ "" => "<empty>"; string => implode (reverse (explode string)); end  [ "abc", "def", "ghi", "" ];

    ["cba", "fed", "ihg", "<empty>"]

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext