Felix rocks. Here's basic comprehensions with parallel iteration that work on every data structure that implements map and zip. No product iteration or guards yet. One problem with this though is that zipping doesn't work across an arbitrary number of items. So, to make this mostly useful we'd need to provide, say, n=1 through 20 zips. Know of an easy way to do this?
comprehensions.flx: ///////////////////////////////// SCHEME """ (define (deflambda sr vars body) `(ast_lambda ((() ((ast_tuple ()) ())) ((,vars none)) typ_none ((ast_fun_return ,sr ,body))))) """; syntax comprehensions { satom := lsqb sexpr vbar comp_parameters rsqb =># """ `(ast_apply ,_sr ((ast_apply ,_sr ((ast_name "map" () ) ,(deflambda _sr (car _4) _2))) ,(cadr _4))) """; comp_parameters := comp_parameter (vbar comp_parameter)* =># """ (list (cons (car _1) (map caadr _2)) `(ast_apply ,_sr ((ast_name "zip" ()) ,(cons (cadr _1) (map cdadr _2)))))) """; comp_parameter := sparameter <- sexpr =># "(list _1 _3)"; } ///////////////////////////////// foo.flx: ///////////////////////////////// #import <flx.flxh> #syntax <comprehensions.flx> open syntax comprehensions; open List; instance[T,U with Show[T], Show[U]] Str[T*U] { fun str (x:T, y:U):string => '(' + (repr x) + ', ' + (repr y) + ')' ; } open[T,U] Str[T*U]; fun zip[T] (xs:list[T]) => xs; fun zip[T,U] (xs:list[T], ys:list[U]) : list[T*U] = { fun aux (xs:list[T]) (ys:list[U]) (acc:list[T*U]) => match xs, ys with | Empty[T], _ => acc | _, Empty[U] => acc | Cons (?x, ?xs), Cons (?y, ?ys) => aux xs ys ((x, y) + acc) endmatch ; return rev $ aux xs ys Empty[T*U]; } val xs = list(1,2,3); val ys = list(4,5,6); val zs = [ x * y | x:int <- xs | y:int <- ys ]; println xs; println ys; println zs; ///////////////////////////////// ------------------------------------------------------------------------- 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