• entries
359
237
• views
189653

# Tangent: Arrow.

186 views

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.]

There are no comments to display.

## Create an account

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.