Loop labels– why don't we have them, and is a macro implementation even possible

88 views
Skip to first unread message

Rezmason

unread,
Oct 8, 2012, 2:06:06 AM10/8/12
to haxe...@googlegroups.com
Thanks to you all, I've now got for loops on the brain. The other day I reached for a tool I'm used to in ActionScript, the loop label, and discovered that Haxe has no equivalent. Haxe's loops are distinctive, so there may be a reason to avoid implementing them, but I'd like to know what that reason is.

That said, I'm not a fan of changing Haxe unnecessarily. It'd be neat to write a macro that added this feature. Unfortunately, I don't think there's any system in place that allows a macro to do this sort of thing– sifting through every module in a project right before their expressions are checked for errors, finding the ones where a for loop (or any scope, actually) is labeled and then doing the macro dirty work. Even if the goal was to implement this for a single class, how would scope labeling work? I guess a labeled scope would be converted into an inline function that's immediately called? Is attempting a macro implementation even worth it?

Nicolas Cannasse

unread,
Oct 8, 2012, 4:16:07 AM10/8/12
to haxe...@googlegroups.com
Le 08/10/2012 08:06, Rezmason a �crit :
> Thanks to you all, I've now got for loops on the brain. The other day I
> reached for a tool I'm used to in ActionScript, the loop label
> <http://blogs.adobe.com/cantrell/archives/2009/12/labels_in_actionscript_3.html>,
> and discovered that Haxe has no equivalent. Haxe's loops are
> distinctive, so there may be a reason to avoid implementing them, but
> I'd like to know what that reason is.

Loop labels are quite similar to goto, you can instead use local named
functions to do that :


function loop() {
for( x in 0...10 )
for( y in 0...10 )
if( x+y == v )
return true;
return false;
}

var found = loop();


Best,
Nicolas


Reply all
Reply to author
Forward
0 new messages