|
|
|||||||
It appears that when one uses an IIF(condition,Exp1,Exp2), both Exp1 and Exp2 are evaluated when only one should be based on the condition. Ruud, could you please alter the current IIF code so that only one expression is evaluted after the condition is checked? |
||||||||
|
|
|||||||
Howard, already been discussed in iif() stack overflow exception "problem"? and Ruud's answer was basically "It's by design" |
||||||||
|
|
|||||||
Bummer Thanks for letting me know. |
||||||||
|
|
|||||||
although, the design could be changed to work as: code:or is that too complex?function iif2($condition,$exp1,$exp2) [ 02. June 2003, 12:22: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
quote:Not complex, but it won't always work. One problem is that IIF() returns arbitrary variable types, while your solution appears to be limited to numeric types. The second problem is variable scope. You will either need to parse variables at the time you call IIF2() in which case it has the same problems as the existing IIF, or you will have to make the variables global. You can get around the arbitrary type by making an assignment in the Execute code:But the variable scope problem is a tougher nut to crack.Exit Execute("$$IIF2="+$exp[not not $condition]) |
||||||||
|
|
|||||||
indeed I forgot that setting of $iif2. but don't understand what you are wondering about vartypes. iif2 does not care about them. don't know what you mean with scope either, as what you put into arg, has the scope of the udf. so, can't see a problem there. {edit} mm... now I think I got what you ment. anyway, see my end comment as it says it really clearly this was just kinda pseudo-presentation that it can be done {/edit} and as final, I didn't mean this as solution. no, I just wanted to show how easy it would actually be to re-design the iif of kix and make it actually usefull. |
||||||||
|
|
|||||||
Other languages which support immediate ifs do it by using a conditional expression, introduced by a ternary (three-part) operator. In that case, because the conditional expression is a language construct rather than a function the result expressions can be conditionally evaluated. Where the solution is provided by a function, whether internal or UDF, you will always have to evaluate both result expressions regardless of the result of the conditional test. |
||||||||
|
|
|||||||
Sorry to reply to such an old thread, but since a recent post was created that referenced this one, which referenced another one from the OLD board I thought I would provide the current link that Jens referenced so others don't have to search for it. iif() stack overflow exception "problem"? #79079 - 08/01/2003 09:27 http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=79079 This post was referenced from a newer post by Bryce here IIF() is executing both conditions http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=122731 |