 |
ReedN Wizard
Joined: 04 Jan 2006 Posts: 1279 Location: Portland, Oregon
|
Posted: Mon Mar 24, 2008 2:39 am
[2.20] Inconsistant operation of the pipe '|' in function calls |
When I send a list to a function outside of an #if statement such as this:
@function1( one|two)
The list one|two is passed correctly to the function. If I call the function inside an #if statement, such as:
#if (@function1( one|two)) {}
In this case it will only pass the first item of the list (one). |
|
|
|
 |
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Mar 24, 2008 3:45 am |
One of the issues zScript has (in my mind) is that it isn't clear (or maybe consistent) as to when evaluations should happen. Looking at the compiled code, it's clear that it's evaluating the argument. You can see the same thing if you do "#SH %eval(one|two)"
Here's the question: without function prototypes, so that it can tell the type of argument being passed, what should it do? Say you create a function whose body is %concat(Result: %1), and you say @function(1 + 2)... should the result be: "Result: 3" or "Result: 1 + 2"?
I think it is less "surprising" if the arguments are evaluated. Isn't it the case that in many places now, you have to quote strings if they are to be strings? So, the proper way to pass a stringlist literal is probably not @function(a|b) but really @function("a|b") |
|
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4790 Location: Pensacola, FL, USA
|
Posted: Mon Mar 24, 2008 4:21 am |
try #IF (@function1( {one|two})) {}
curly bracets is how you define an anonymous stringlist in a trigger |
|
|
|
 |
ReedN Wizard
Joined: 04 Jan 2006 Posts: 1279 Location: Portland, Oregon
|
Posted: Mon Mar 24, 2008 4:24 am |
http://forums.zuggsoft.com/forums/viewtopic.php?t=30145
| Fang Xianfu wrote: |
Almost certainly a bug - like I said, it's performing or evaluation. Or returns the first item if it's true and the second item if it's not. You're getting the first because it's the result of an or operation. But the or operator was changed from | to || in CMUD, presumably to stop exactly this kind of thing from happening. So something's wrong that's making CMUD still use | for or.
It should work fine if the stringlist is in a variable, and if it's not, you can just put quotes round it, anyway. |
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Mar 24, 2008 4:29 pm |
In CMUD, you need to get used to putting "" around string values, or {} around string lists. Because in your above example, it is ambiguous whether the first element in your string list is "one" or " one" (with a leading space). That is why you should use {one|two} to avoid confusion with extra spaces.
|
|
|
|
 |
ReedN Wizard
Joined: 04 Jan 2006 Posts: 1279 Location: Portland, Oregon
|
Posted: Mon Mar 24, 2008 10:17 pm |
It functioning in one way outside an #if statement and another way inside the #if statement isn't a bug? I can use {} to mark the list, but it seems strange that it does different things depending on where it is located.
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Mar 24, 2008 11:20 pm |
That's what is meant by "undefined". When you try to do something that is outside of the normal syntax, then the results are undefined. That's because it depends upon the low-level internal details of the parser as to whether it's going to take the space before "one" as part of the list item or not. So it might work one way when the parser is looking for an expression (like with #IF), and a completely different way when looking for a function argument (which defaults to a string value).
|
|
|
|
 |
|
|
|