On Sat, 2006-09-30 at 01:18 -0700, Erick Tryzelaar wrote:
> Say I wanted to implement a generator like this:
> 
> gen f () ():int = {
>   iter (proc (i:int) {
>     yield i;
>   }) (1,2,3,4);
> 
>   // to fool felix
>   return 0;
> }
> 
> 
> Now, felix isn't happy because yield is trying to yield from the inner 
> function. Is there any way to lift the yield so that it can be used 
> inside of an inner function, yet still allow yielding out from the outer 
> function?


Yes, you can lift it .. it's messy .. note first you can't
yield from a proc, it has to be a generator function.

So you can just 'pass the buck'

gen f():int {
        gen y():int { ... yield ... }
        yield y();
}

This is the same as you'd do with return:

fun f(): int {
        fun y(): int { ... return .. }
        return y();
}

If you want to use an iteration procedure you can .. but you
use fibres/channels. Unfortunately, you can't mix them:
generators are functions and use the machine stack,
so they can't be used to read or write channels.

Interestingly it will WORK most of the time, provided
the function is inlined into a top level procedure.
I've a good mind to make:

inline gen ..

mandatory .. that converts a function to procedural code
by changing return to an assignment. but you can't
inline recursive things fully (you can unfold once).
Unless they're tail-rec of course.

It would be so nice to get rid of C functions.. the
machine stack is a real pain :)
        
-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to