Lambda with short syntax powered by macros

187 views
Skip to first unread message

Ed Ryzhov

unread,
Jul 13, 2013, 1:41:47 AM7/13/13
to haxe...@googlegroups.com
Hi, just wanted to let you know that I wrote a small library that implements the lambda via macros.


Tests show an increase in performance compared to a conventional lambda to 20 times.
Link to the test - http://gametrax.eu/game/35a3c97a95 (warning, can be slow!)

Hope someone finds it useful, especially for games.

And thanks to Simon Krajewski for hxshort.

Best,
Ed.

Simon Krajewski

unread,
Jul 13, 2013, 3:11:45 AM7/13/13
to haxe...@googlegroups.com
Am 13.07.2013 07:41, schrieb Ed Ryzhov:
> Hi, just wanted to let you know that I wrote a small library that
> implements the lambda via macros.
>
> It is here - https://github.com/ryzed/LambdaMacro
>
> Tests show an increase in performance compared to a conventional
> lambda to 20 times.
> Link to the test - http://gametrax.eu/game/35a3c97a95 (warning, can be
> slow!)
>
> Hope someone finds it useful, especially for games.

Looks good!

You may want to change your arguments from Expr to ExprOf<Iterable<T>>
etc. so completion doesn't show up in inappropriate places. Also, you
have to consider empty iterables when working with code like
"$a.iterator().next()", which may return null.

Simon

Ed Ryzhov

unread,
Jul 13, 2013, 6:32:55 AM7/13/13
to haxe...@googlegroups.com
On Saturday, July 13, 2013 11:11:45 AM UTC+4, Simon Krajewski wrote:
Also, you have to consider empty iterables when working with code like  
"$a.iterator().next()", which may return null. 
This is a trick to infer the type, it is not executed at runtime.
For example this code:
class NullIteratorTest
{
public function new() { }
public function hasNext():Bool return false;
public function next():Int return 0;
}
class NullIterableTest
{
public function new() { }
public function iterator():NullIteratorTest return null;
}

var t:NullIterableTest = null;
var a = t.array();
will generate correct code and show runtime null pointer exception as usual.

But you're right, I added a checks to the impossibility of type inference.
And completion hints too.

Best,
Ed.

Simon Krajewski

unread,
Jul 13, 2013, 6:58:22 AM7/13/13
to haxe...@googlegroups.com
Why do you have to manually infer the type at all?

Simon

Ed Ryzhov

unread,
Jul 13, 2013, 7:13:33 AM7/13/13
to haxe...@googlegroups.com
Why do you have to manually infer the type at all?
I thought I would need to specify the type when I create a List<T>, never used it.
Now checked, there is no need.
Thanks, I'll fix it.

Reply all
Reply to author
Forward
0 new messages