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
Zugg
MASTER


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

PostPosted: Tue Nov 20, 2007 12:04 am   

Should Aliases be allowed to change the scope/context
 
OK, I hope this is another easy question that we can get consensus on. Consider the following script:
Code:
#ALIAS change {#CLASS MyClass}
#ALIAS test {#SHOW "Start:" %class;change;#SHOW "Finish:" %class}

OK, now what should the "Finish" class be? In other words, when the "change" alias changes the current class using #CLASS, should this persist back to the *calling* script? Or should scripts do an automatic "#CLASS 0" at the end?

The same question holds when using the #MODULE command to change the current module/package.

The reason I bring this up, is imagine that the "change" alias above is in some other package that you have loaded, and the package designer forgot to put the #CLASS 0 at the end of their script. Now the context has suddenly changed back in your own scripts, and you might start accessing the wrong variables or aliases.

Remember that clicking on the command line already restores the current class and module (it does a #CLASS 0 and #MODULE 0). So we are just talking about within a running script that calls another script.

Also imagine a Trigger or Event that runs and changes the #CLASS. Should that change persist after the trigger and/or event has executed?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Nov 20, 2007 1:39 am   
 
It's always been the case in the past that you need to be careful to use #class 0 after you've used #class to change the current class (unless you deliberately intend not to). I don't see why this should be an exception.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Nov 20, 2007 1:49 am   
 
Quote:
unless you deliberately intend not to

I guess that is what I was getting at. Is there a reason someone would want to change the #class for the entire calling script on purpose? Otherwise it just seems like it would be a good idea if CMUD cleaned this up for you so that a bad script was limited in the amount of problems it creates.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Nov 20, 2007 1:54 am   
 
My gut reaction was that the scope should have remain unchanged, but after thinking about it more, scripts should do an automatic '#CLASS 0'. It's more in line with other programming languages and I wouldn't want other errant scripts changing my scope access. In general, I don't assume any context unless I explicitly set it within my scripts.

I did want to confirm that if I had this code
Code:
#ALIAS change {#CLASS MyClass}
#ALIAS test {#SHOW "Start:" %class;change;#SHOW "Finish:" %class}
#ALIAS test2 {#CLASS TestClass;test}

And I called the 'test2' alias that "Start" woud should TestClass and "Finish" would show TestClass.
_________________
Asati di tempari!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Nov 20, 2007 11:30 am   
 
I think Tech has hit a good point. Rather then being an automatic #CLASS 0, it really needs to be something that is put into the call stack. That way at the start of a script it pushes the current module and class path, then at the end of a script it pops them. This will likely give the most consistent behavior.

Doing just #CLASS 0 leads to a possible situation where the a #CLASS command by the end user is getting lost or ignored.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Nov 20, 2007 2:59 pm   
 
OK, if I get this right.

I start out my alias script with a class scope change.

#class A
Run a few commands that I want to execute within this scope.
Call another alias that will run in its own scope and do its own thing.
Run more commands that I want executed within this scope.
#class 0

If an automatic #class 0 is placed at the end of an alias then I'm going to lose my scope for the line.

"Run more commands that I want executed within this scope."

I think that Vijilante's Idea of having a record of where the scope was when it wasn't closed is a better idea. But we need some sort of end game that draws the line on when the scope is set to 0.

Perhaps with the last } of the uppermost alias is called.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Nov 20, 2007 3:03 pm   
 
Maybe it would be cleaner to just state that if you call an alias/function within a #class block that you need to start a new #class because you have lost your scope. Confused
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Nov 20, 2007 5:39 pm   
 
Sorry I got people sidetracked with the #CLASS 0 comment. What I really meant was what Vijilante already mentioned...that an alias call would push the current context and then pop it when it was done. Sorry I wasn't more specific.

Anyway, it sounds like I'm on the right track here and that nobody wants the context changed by an alias to effect the calling script.
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 873
Location: USA

PostPosted: Tue Nov 20, 2007 7:16 pm   
 
Zugg wrote:
Sorry I got people sidetracked with the #CLASS 0 comment. What I really meant was what Vijilante already mentioned...that an alias call would push the current context and then pop it when it was done. Sorry I wasn't more specific.

Anyway, it sounds like I'm on the right track here and that nobody wants the context changed by an alias to effect the calling script.


Yes. Letting an alias change the namespace that the calling code is sitting in would be kind of hard to wrap my mind around.

-Tarn
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4708
Location: Pensacola, FL, USA

PostPosted: Tue Nov 20, 2007 7:46 pm   
 
I could see an alias moving an item between classes with a new command.

#MOVEITEM {ID} {NewClassName}
_________________
Discord: Shalimarwildcat
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