 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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. |
|
|
|
 |
kjaerhus Magician

Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: 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
|
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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.
|
|
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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. |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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. |
|
|
|
 |
|
|
|