🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Arrow.

Published March 18, 2009
Advertisement
Had the day off to take care of some errands. I tend to lack motivation, so recharge days are vital. Then I spent a whole lot of time banging my head against stupid bugs and little awkward problems. So not a lot of progress...

Then I got fed up with it and implemented new stuff. A whole 5 minutes later, and the arrow operator exists. The arrow operator (->) is a type-expression operator. It takes two types and creates a static method signature as you might expect:

public static	test(int x) => void {	print x;}public static	main() => void{	local int -> void   op = test;	op(5);        // 5}


Or, a more complex example which is still not as elegant as list comprehensions...

public static	elements in (IEnumerable<int> collection) where (int -> bool  predicate) => yields<int> {	foreach( int x in collection ){		if( predicate x ){			yield(x);		}	}}public static	(int min) to (int max) => yields<int> {	local int counter = min;	while( counter < max or counter equals max ){		yield(counter);		counter = counter + 1;	}}public static	(int n) is even => bool {	return( n%2 equals 0 );}public static	main() => void{	foreach( int x in elements in 3 to 10 where (int n) => bool{ return( n is even ); } ){		print x;	}}


Which would be sweet if it worked. There's a bug with yielding from within an if block which the last hour has not fully diagnosed. Still; a few people were looking for more complex examples, and there you go.

[edit: 90 minutes, no progress on the bug. It is a problem for blocks not resetting their execution pointers as they should after a yieldy block is restarted. Should be more simple when I can think again. It is the same problem I had earlier with nested loops and yield blocks. if stuff is a little more nuanced since you don't know when/if it's restarted via loop.

Definitely makes the .NET switch/jump hack look a lot more elegant.]

[edit2: the second example now works properly.]
Previous Entry Links and progress
Next Entry Tangent: Enums
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement