Question
When the following code is executed rather than "firstday" getting set to 1 as it should it is set to the value specified in the last $SET, even though only one should get evaluated.
1. %CALC{"$SET(day,Monday)"}%
2. %CALC{"$IF($EXACT($GET(day),Monday) == 1,$SET(firstday,1),not Monday)"}%
3. %CALC{"$IF($EXACT($GET(day),Tuesday) == 1,$SET(firstday,2),not Tuesday)"}%
4. %CALC{"$GET(day)"}%
5. %CALC{"$GET(firstday)"}%
Produces this:
-
-
- not Tuesday
- Monday
- 1
Any ideas why???
Thanks
Environment
| TWiki version: |
|
| TWiki plugins: |
Spreadsheet plugin |
| Server OS: |
Redhat Linux |
| Web server: |
|
| Perl version: |
|
| Client OS: |
Windows 2000 |
| Web Browser: |
Internet explorer 6 |
--
ThomasDearden - 01 Mar 2004
Answer
This is a feature/bug of the current implementation. The Plugin simply evaluates all nested functions recursively, then does the IF/THEN/ELSE logic. That is, both THEN and ELSE are evaluated, but only one of them is returned. This is fine if you return a string, but fails if you want to set a variable conditionally.
I do not know of a workaround at this time. The Plugin logic could be changed to make it aware of the special IF case.
--
PeterThoeny - 04 Mar 2004
Just found out there is a way.
- Instead of:
$IF(condition, $SET(var, foo), $SET(var, bar))
- Write:
$SET(var, $IF(condition, foo, bar))
--
PeterThoeny - 04 Mar 2004