I thought I'd try a stream filter:
//////////////
gen f ( var g : 1 -> opt[int] ) () : opt[int] = {
match ?x when x > 10 in g() do yield Some x; done
return None[int];
}
var x = list (99,88,1,5,10,15,2,6,11,16);
var y = list$ f x.iterator;
println$ y;
////////////////////
This compiled but didn't work. So there's a warning here:
the syntax allows the argument of an iterator to be:
(a) A function 1 -> opt[T]
or
(b) Any data structure with an iterator method.
Now, g() returns an opt[intt] and I recall Dobes implemented a clever
trick from Scala:
lib/std/option.flx:
// Make option types iterable. Iteration will loop once
// if there is a value. It's a handy shortcut for using
// the value if you don't care about the None case.
gen iterator[T] (var x:opt[T]) () = {
yield x;
return None[T];
}
So this just yields 99 and then terminates.
A very interesting conjunction of syntactic sugar which allows bugged
to code to actually compile and run ... but give unexpected results!
Anyhow, the correct code:
match ?x when x > 10 in g do yield Some x; done
works fine. I have to say I found it very hard to remember the syntax:
for i in iterator do .. done
is easy and the match variant just replaces
for i
with
match ?i
but still I kept getting confused.
Anyhow, it should be easier to write this filter.
Something like
stream (g:stream) => match ?x when ?x > 10 in g
i.e. you shouldn't have to write yield, nor Some.
The syntax should suggest a comprehension:
{ ?x when ?x > 10 | g }
which is the "usual" notation for a set.
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language