PreviousUpNext

5.4.8  Mythryl Functions: Thunk Syntax

When creating fates and callbacks, there are times when the standard

    \\ () = 14;

syntax is uncomfortably distracting.

For these cases Mythryl offers the alternative syntax

    {. 14; };

That looks a little odd, but efficiently leads the reader’s eye to focus on the important central expression rather than the surrounding syntactic noise.

The two forms are semantically entirely equivalent; the compiler internally expands the latter to the former very early in processing.

Sometimes such microfunctions need parameters. For example, often a sort routine will take as argument a comparison function defining the collating order:

    sort  (\\ (a,b) = a < b)  [ 1, 2, 3 ];

In such a context, the
syntax is again rather distracting. With a tip of the hat to Perl, Mythryl supports an abbreviation syntax here similar to that of the preceding case:

    sort  {. #a < #b; }  [ 1, 2, 3 ];

The brevity of this form seems a better fit to the setting.

Again, the two versions of the syntax are entirely equivalent semantically, the compiler internally expanding the latter into the former very early in processing.

A prime motivation for the latter syntax was the desire to support iteration functions which may effectively be used in place of conventional loop syntax.

For example, the syntax

    foreach  (1..n)  \\ i = {
        printf "%d\n" i;
    };

is visually not particularly appealing; a distinct improvement is obtained by substituting:

    foreach  (1..n)  {.
        printf "%d\n" #i;
    };

The reader’s eye now moves naturally to the significant content, largely undistracted by syntactic noise.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext