You can now do this in Felix:

val x = ( println$ 1; 1 );
println$ x;

Inside parens () a semicolon now acts like an infix operator whose LHS
must be an expression of type void. This is very similar to the C comma
operator.

More precisely the grammar is:

  satom := "(" stmt+ sexpr ")" 

which means this works too:

val y = ( for var i in 0 upto 3 do println$ 1; done 1) + (println$ 2; 2);

The actual definition is:

        ( stmts value ) --> { stmts return value; } ()

If you omit the leading statements you get this:

        ( value ) --> { return value; } ()

which is consistent. You cannot use the semi-colon operator in
free text, that is, you have to put the parens. This doesn't work:

        x = print 1; 2;

because it looks like:

        x = print 1;
        2;


Note that 

        (stmts value) --> #{stmts value}

since

        #expr --> expr ()


So we now have about 200 ways to write the same thing :) :)

This new syntax is very useful, however. For debugging consider:

        val x = match a with
        | pattern => value
        | pattern2 => value2
        endmatch;

If you wanted to put in a debug print to say which branch was taken in the RHS 
you're
pretty screwed! You cannot put in a print, because its a statement. You could 
do this:

        | pattern => #{ print "first"; return value; }

which is pretty messy, especially when you want to comment out the debug. 
The new syntax is a minor improvement:

        | pattern => ( print "first"; value )

because:

        | pattern => ( /* print "first"; */ value )

you can easily just comment out the debug and get back where you started.

It's not as seamless as:

        | pattern => second { print "first"; } value

where

        gen second[T] (p:1 -> 0) (x:T) = 
        {
                p;
                return x;
        }

which would allow:

        | pattern => /* second { print "first"; } */ value

because our new notation might require adding parens,
the second function only requires inserting and eliding
prefix text (no trailing paren).

Note that at this time you cannot do this:

        ( print 1; print 2; )

Also you cannot do this:

        #{ print 1; print 2; }

even though you can do this:

        { print 1; print 2; };

and this:

        { print 1; print 2; } ();

The problem is that {} () is an expression of type void and that is not
permitted. You can do

        p x;

where p x is of type void, but only because that means

        call p x;

and not

        apply (p,x);



--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to