• entries
    359
  • comments
    237
  • views
    188615

Tangent: foreach.

Sign in to follow this  

63 views

I finished a working solution to the nested block variable access bug. Probably not the best solution, but it works. As you might expect by the name, variables declared more than two blocks deep now don't cause runtime errors.


That also means C# style foreach now works:


public static void main(){
local List<int> foo = new List<int>;

foo.Add(1);
foo.Add(2);
foo.Add(3);

foreach( int x in foo ){
print x; // 123
}
}





A functional style foreach will have to wait until method generics work a little better. Next on the list is making yield work. Maybe tonight, probably not.
Sign in to follow this  


2 Comments


Recommended Comments

Looks an awful lot like C++/C# [smile] That's a good thing though, it will make it easier for people with those backgrounds to easily get into Tangent.

Of course, what's happening under the hood is not really apparent from this point of view, but that's only a good thing IMO.

Share this comment


Link to comment
Quote:
Original post by Jotaf
Looks an awful lot like C++/C# [smile] That's a good thing though, it will make it easier for people with those backgrounds to easily get into Tangent.


That's the idea. Plus the original goal was to make C# with first class functions; things kinda expanded from there. And since .NET objects can be used from within the language it needs to provide the same sort of mechanisms, so they might as well follow the same sort of syntax.

Quote:

Of course, what's happening under the hood is not really apparent from this point of view, but that's only a good thing IMO.


Indeed, though to be honest foreach doesn't really behave under the hood any differently (besides the lack of automated casting) than it does in C#. No need to change something that works well.

Share this comment


Link to comment

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