Tags:
create new tag
view all tags

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:

  1. not Tuesday
  2. Monday
  3. 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

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2004-03-06 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.