On Fri, 2006-09-08 at 00:21 -0700, Erick Tryzelaar wrote:
> skaller wrote:
> > Felix now supports first class iterators, as a special
> > case of generators. Here is an example:
> 
> Thats so awesome. Much better than my streams :) 

Don't be so sure. The fibres/channels subsume everything
that can be done on a uniprocessor and there's extremely
efficient -- it's just that you have to write entirely
procedural code to use them.

The generators don't replace your streams: together with
the mk_ioschannel_pair function, these two things were
put in so you could get a better streams implementation.

> A couple comments on 
> the syntax. First off, python is just about to add sending data back to 
> their generators, but they're using a slightly different to receive data 
> from the calling function. They use the equivalent of "val inc = yield 
> counter;". Did you consider that syntax? 

It's already supported: however the sendback data is stored
in the function parameter, not returned by the yield statement.

When you call the function to resume .. you can pass a new
argument already.

> The second is related. The 
> overloading of the curry syntax throws me off a little. 

There is no overloading: currying is the same as before.
A generator is just like a function, in fact it is a function,
with relaxed rules about side effects plus the fact calls
through variables don't clone.

> Using the 
> curry-style argument list may suggest to a newbie that you could do "var 
> x = f 5 10;" to get one result.

You can! You just can't get any more results, because you didn't
save the closure!

> Finally, the best way to signify the end of the generator still seems to 
> be to wrap things in opt. 

That's the canonical way to convert a list into a stream.

> Is this the fastest way we can signify the 
> end, or are there any compiler-side tricks that can be done to optimize 
> things?

I plan to enhance the optimiser so 'opt' will use a single 
pointer with the low bit as the variant tag:

        000000000 --> NULL -> None
        xxxxxxxx1 --> Some x


In fact, the optimisation is: calculate how many spare bits
there are in a pointer to maximally aligned heap objects,
typically heap is aligned 16, which means 4 bits.

Then, variants with 16 or less cases fit in one machine word
instead of two.

Variants are always boxed though. This might be fixed
for 'small enough integer' variants, using the same trick:
split up the machine word into the tag an the integer.

Expanded (unboxed) variants are also possible but that's
a bit harder.


> 
> > Note the new keyword 'gen' which denotes a generator.
> > A generator is any function with internal state.
> > C bindings must also be declared generators if they
> > access state, for example: malloc(), random() etc are generators.
> > All class constructors are also generators.
> 
> Are you referring to it as being conceptually generators, or that you're 
> actually going to change the library to reflect this?

Both :)

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to