Please note change in syntax: you cannot say for var k in .. now, "var" isn't allowed. Note the control variable is invisible outside the loop. This is a worry .. it suggests the body is in a function. Simple examples work though. So here's the current state:
1. Iterators work for all arrays and lists: for k in list(1,2,7) do println$ "l elt=" + str k; done for k in 1,2,3 do println$ "a elt=" + str k; done for k in varray(1,6,3) do println$ "v elt=" + str k; done for k in darray(1,82,3) do println$ "d elt=" + str k; done; 2. You can do a yield inside an iteration body: gen silly () = { for k in (1,2,3) do yield k; done return 99; } var ff = silly; println$ #ff; println$ #ff; println$ #ff; println$ #ff; println$ #ff; Note, I am not sure if this always works! Normally you cannot yield or return inside a nested function, even one which is implicitly generated and that *includes* the handler of a match case and therefore the body of an iterator loop (because it matches Some/None). In principle the handler of a statement match is a procedure, I'm not sure if it's luck it got inlined, allowing the yield, or the compiler forces the code into line (note: the control variable k is hidden suggesting inlining, rather than desugaring, is handling this). Note that generator implicit procedures like this are ALWAYS marked for inlining, and they should be even if they're scoped inside a function they call recursively (Felix inlines children which recurse to their parents into the parent). 3. So .. this needs to be double checked because it is used to do this: gen stream () = { for k in (1,2,3) do yield Some$ k+40; done return None[int]; } var ll = comprehension stream; println ll; Here "comprehension" is a list comprehension. It looks fairly useless until you see it inline: var zz = comprehension { for k in (9,2,3) do yield Some$ k+40; done return None[int]; }; println zz; It's not far to go to define this: ctor[T] list[T](f: (1->opt[T])) => comprehension f; var kk = list { for k in (11,7,3) do yield Some$ k+40; done return None[int]; }; println$ kk; and we can do that without any further syntax extensions. They're a nightmare, it took 6 hours to get 20 lines of Scheme right :) BTW: I have no idea about performance but I guess this style of code is likely to be SLOW because it uses closures in a way that can't really be inlined. It's pretty obvious we can now do: for k in subrange (0,20) do .. so we no longer need "for .. upto .." loops (although that's how I'd implement subrange .. it can be done with gotos if necessary :) LAZINESS -------------- One of THE important things about comprehensions in Haskell is that they're lazy. The list comprehension I gave above is not. In fac t you should note that an iterator is already lazy and the whole point of the comprehension is to wake it up .. the generator is **already** a lazy thing. In fact it is polyadic .. it isn't a lazy list, it's much better than that, its a lazy array too. OPERATORS ------------------- As is known from C++, iterators have some nice properties, one of the cutest is the fact you can plug them together in series. I won't demonstrate, it's obviously just "yield f x; " i.e. fiddled around function composition. Obviously you can compose iterators in parallel too. in fact, you can basically do anything with them you can with functions .. since they are basically "control inverted" functions. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language