This is so cool. Here's very very basic list comprehensions:

comprehensions.flx:
syntax comprehensions {
  satom := lsqb sexpr rsqb =># (List::list _2);
  satom := lsqb sexpr vbar sname <- sexpr rsqb =># """
    `( ast_apply
      ,_sr
      ( ( ast_apply
          ,_sr
          ( ( ast_lookup (( ast_name "List" () ) "map" () ) )
            ( ast_lambda
              (
                ( () ( ( ast_tuple () ) () ) )
                ( ( ( ( PVal ,_4 ( ast_name "int" () ) ) ) none ) )
                typ_none
                ( ( ast_fun_return ,_sr ,_2 ) )
                ) ) ) )
       ( ast_name "xs" () ) ) )
  """;
}



foo.flx:
#import <flx.flxh>
#syntax <comprehensions.flx>
open syntax comprehensions;

val xs = [1, 2, 3];
val ys = [ x * 3 | x <- xs ];

print ys;
endl;


result:
// Save Syntax file ./comprehensions.flx.syncache
WHA?? Parent 4048 of 4051 does not exist??
WHA?? Parent 1778 of 1783 does not exist??
[3, 6, 9]


Now, I just need to figure out how to not hardcode the name of the
list and the type of the inner function. If I replace the "xs" with
,_6, it errors with:

// Save Syntax file ./comprehensions.flx.syncache
CLIENT ERROR
[lookup_name_in_env]: Name 'ast_name' not found in environment (depth 2)
In ./foo.flx: line 6, cols 1 to 29
5: val xs = [1, 2, 3];
6: val ys = [ x * 3 | x <- xs ];
   *****************************
7:

Not sure how to fix it yet. I'm also not sure how to get the syntax to
be like this to not hardcode the type:

val ys = [ x * 3 | (x:int) <- xs ];

Although it'd be better if felix could determine the type :)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to