• entries
359
237
• views
189396

# Tangent: foreach.

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

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.

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.

## Create an account

Register a new account