PreviousUpNext

5.7.10  Mythryl Code Blocks

The original C block syntax required all declarations to precede all statements:

    { int i = 12;
      float f = 1.0;
      printf("%d %f\n", i, f);
    }

This proved very unpopular in practice, and first C++ and then C99 relaxed the syntax to allow arbitrary interleaving of declarations and statements within a code block.

    { int i = 12;     printf("%d\n", i);
      float f = 1.0;  printf("%f\n", f);
    }

A somewhat similar progression may be observed in SML. Officially, let syntax supports only declarations followed by statements:

    let val i = 12
        val f = 1.0
    in
        format "%d %f\n" [ INT i, REAL f ]
    end

What one sees in practice, however, is syntax like

    let val i = 12      val _ = format "%d\n" [ INT i ]
        val f = 1.0 in          format "%f\n" [ REAL f ]
    end

where it is perfectly clear that the intent of the programmer is to interleave declarations and statements freely via the val _ = ... hack, whatever the clear intent of the language designers.

Mythryl code blocks are patterned syntactically after C code blocks, but are derived forms which internally expand into standard ML let statements via the above val _ = ... hack. To some extent, this gives Mythryl the best of both worlds; the application programmer gets the freedom of interleaving declarations and statements in natural order, while the Mythryl theoretician still gets the analytical perspicuity of the let form (since theoreticians dismiss derived forms from consideration).

Thus, the Mythryl equivalent of the above is

    { i = 12;     printf "%d\n" i;
      f = 1.0;    printf "%f\n" f;
    }

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext