Page 1 of 1 1
Topic Options
#81664 - 2003-06-02 04:16 AM IIF enhancement
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#81665 - 2003-06-02 04:21 AM Re: IIF enhancement
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Howard, already been discussed in iif() stack overflow exception "problem"? and Ruud's answer was basically "It's by design" [Smile]
_________________________
There are two types of vessels, submarines and targets.

Top
#81666 - 2003-06-02 04:44 AM Re: IIF enhancement
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Bummer [Frown] Thanks for letting me know.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#81667 - 2003-06-02 11:20 AM Re: IIF enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
although, the design could be changed to work as:

code:
function iif2($condition,$exp1,$exp2)
dim $exp
$exp=$exp1,$exp2
exit execute($iif2 = $exp[not not $condition])
endfunction

or is that too complex?

[ 02. June 2003, 12:22: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#81668 - 2003-06-03 12:16 AM Re: IIF enhancement
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
quote:
or is that too complex?
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:
Exit Execute("$$IIF2="+$exp[not not $condition])

But the variable scope problem is a tougher nut to crack.

Top
#81669 - 2003-06-03 12:28 AM Re: IIF enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 [Wink]
this was just kinda pseudo-presentation that it can be done [Razz]
{/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.
_________________________
!

download KiXnet

Top
#81670 - 2003-06-03 12:48 AM Re: IIF enhancement
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#81671 - 2004-07-26 10:10 PM Re: IIF enhancement
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.056 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org