TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

#regex - change &1, &2 etc to %1, %2, etc?

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
mrbigtaco



Joined: 26 Jun 2011
Posts: 54

PostPosted: Fri Nov 30, 2012 4:06 pm    Post subject: #regex - change &1, &2 etc to %1, %2, etc? Reply with quote

Is there a technical reason for why the #regex results are stored in &1, &2, etc binding points instead of %1, %2, etc like all the other parts of tt? I had some early experience attempting to use #regex for parsing text after capturing it from the mud (inside actions, loops, etc) but ended up running into mutex problems with the results in &1, &2, etc being overwritten by other #regexs firing in other places before I could read the values inside the code block in which they belonged. At least if they were %1, %2, etc they should have guaranteed local scope?

From my perspective it seems like there's a strong case for converting based on:
1) would be more consistent with the conventions used by other tt commands
2) should enforce local variable scope - no more mutex concerns
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Fri Nov 30, 2012 9:59 pm    Post subject: Reply with quote

You'd have the same problem if % was used.

One work around is storing the values in a variable. I guess I could make the variables local. I'll add it on my todo list as a project for a rainy day.
Back to top
View user's profile Send private message Send e-mail
mrbigtaco



Joined: 26 Jun 2011
Posts: 54

PostPosted: Fri Nov 30, 2012 10:59 pm    Post subject: Reply with quote

I may have just not tried hard enough, but so far values in %1, %2, etc have remained valid within a single #action / #alias block, even when looped over (haven't yet had a problem with them being overwritten by something else). In my testing with #regex's &1, &2, etc the values were being overwritten before I could store them in a local variable, so it was a fairly big problem to not even get a chance to read them. I interpreted this as because of &1, &2, etc style being more like global pointers, but that's without digging in to the code to see what's actually going on for a post mortem.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Sat Dec 01, 2012 8:57 am    Post subject: Reply with quote

If you're nesting a regex inside another regex try using &&1 &&2 for the 2nd regex.
Back to top
View user's profile Send private message Send e-mail
mrbigtaco



Joined: 26 Jun 2011
Posts: 54

PostPosted: Sat Dec 01, 2012 6:10 pm    Post subject: Reply with quote

I think the specific case I was having problems with was something like

#alias somealias {
#regex (
do stuff to process
)
call somealias recursively with more stuff to process
}

The process was being kicked off by an action grabbing text to process, and then feeding it into the alias to recursively process- it's a lot simpler to use the regex to do the processing, but for whatever reason the results became unpredictable in a hurry (even with debug statements to see what the input to the regexs were and taking into account valid matches, the contents of &1, etc inside the body of the regex were values from other code blocks, completely unrelated).
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Sun Dec 02, 2012 9:23 am    Post subject: Reply with quote

I'd have to see an example, but there's probably some work around using a stack or a variable to store the result.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Mon Dec 03, 2012 8:22 am    Post subject: Reply with quote

Is it unreasonable to consider whether there could be local variables on a more general basis? For use inside #FUNCTIONS and #ALIAS perhaps? Particularly for the former where one goes to the care of passing in values when it is called, it seems un-"Function-like" that it can use/change ANY variable and as I have found in the past it can be awkward if one is using a #FUNCTION recursively to avoid variable name collisions with other instances of the same function. Confused
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group