Jump to content
  • Advertisement
  • entries
    359
  • comments
    237
  • views
    189653

Tangent: Arrow.

Sign in to follow this  
Telastyn

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.]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!