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
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Feb 06, 2008 5:42 pm   

[2.18] Bug in %param
 
%param is behaving very oddly. Take the following commands (I've tried this in both an active session and a blank session):

#alias testparam {$n = 2;#say %param(2);#say %param($n);#say %param(%numparam())}
testparam a b

I would expect 3 lines of "b", but instead I get:
b
a
a b

%param seems to only work when the parameter is a literal number.
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Wed Feb 06, 2008 5:56 pm   
 
Is not a bug - is a feature... ;-)

No, I agree it must be a bug. It seems you can work around it by using #VAR though:
Code:

#alias testparam {#VAR n 2;#say %param(@n);#UNVAR n}
testparam a b
#unalias testparam
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Feb 06, 2008 6:07 pm   
 
I'm not surprised that %param($n) doesn't work, because %param accepts a *name* in addition to just a number. So when using named arguments, you want %param($argname) to work properly. But I'm surprised that the %param(%numparam()) doesn't work, so I'll add that to the bug list.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Feb 06, 2008 6:54 pm   
 
For anyone reading who might want to use a local variable in %param, I found a workaround:
Instead of %param($a), use %param(%eval(0+$a))

%param(%eval(0+%numparam()) can be used as a workaround until Zugg fixes that particular bug.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Wed Feb 06, 2008 7:11 pm   
 
Zugg wrote:
when using named arguments, you want %param($argname) to work properly


I think that depends on your definition of "properly". In every other context in CMUD, local variables are expanded and then passed to the function - if you wanted to use the literal string "$argame", you could quote it so that it really is a literal string, and avoid the ambiguity.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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