On Sun, 2007-08-26 at 02:13 -0700, Erick Tryzelaar wrote: > 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?
> val xs = list(1,2,3); > val ys = list(4,5,6); > val zs = [ x * y | x:int <- xs | y:int <- ys ]; If you fold the zip application, you will get a list of elements like: (a, (b, (c, d))) instead of a flat tuple .. but that is actually what you want, because you can 'unpack' it recursively. The 'real' problem here is that tupling is an N-ary constructor which can't be generalised over N. In Ocaml, using the internal representation, generalising it is trivial, since a tuple is just a list, so it can be unpacked recursively with the usual | h :: t -> f h op aux t kind of thing, in particular folds. But there is no way for the user to write this code in Felix.. It CAN be written in Scheme though. In particular, nugram.flxh already provides a fold_left function. Anyhow .. my suggestion is simply to fold the binary zip in Scheme, that is, use Scheme fold_left I implemented to generate (zip a (zip b (zip c (zip d e)))) The comprehension is a single fold, but now with a nested matching also generated by Scheme with the same pattern: match elt with | ?a,(?b,(?c,?d)) => formula_involving (a,b,c,d) endmatch Of course this is the Felix representation .. the Scheme representation will be a bit nastier. BTW: I would like to add a new feature to Scheme .. pattern matching. Using car, cadr, etc etc to decode is list is just rubbish. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- 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