Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Tarn
GURU


Joined: 10 Oct 2000
Posts: 873
Location: USA

PostPosted: Tue Oct 17, 2006 3:45 pm   

FORALL and looping
 
What's the current state of looping variable syntax?

There was a thread discussing IF and WHILE using the new function %exp that lets you get at the current block's argument stack:
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=24449&highlight=forall

My comments are the FORALL version of Asira's post in that thread.

The new feature doesn't seem to apply to FORALL loops (which, granted, don't have parentheses but could benefit from similar treatment):
#var list "a|b|c"
#var count 0
#forall @list {
#echo %exp(0);
}

as an alias gives a series of blank lines.

The %i syntax gives results that could be a bit confusing to new users. Define one alias named "test5":
#var list "a|b|c"
#var count 0
#forall @list {
#echo %i;
}

One would expect it to output a series of lines saying "a", "b", "c" (it does).

Define another alias named "test6":
#var list2 "q|w|e"
#FORALL @list2 {
#echo %i;
test5;
}

Calling test6 outputs the series of lines "q","q","q","q","w","w","w","w","e","e","e","e"

Is this intentional behavior? (acting almost as if test5 had been expanded inline instead of being a separate namespace)

Changing the %i in test5 to %j gives the expected result of "q","a","b","c","w","a","b",...

Tarn
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Oct 17, 2006 4:59 pm   
 
The loop variables work as they do in zMUD (or should). %i always refers to the outermost loop, %j the next inner loop, etc. Doesn't matter how they are nested, or even if they are nested indirectly like you showed. Yes, it can be confusing, but it's a compatibility issue.

It's possible I will improve this with some sort of local variable solution like I did with %exp, but since we are getting closer to a public release, I don't want to make anymore parser changes right now.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net