AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ternary Operator Documentation

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
tuna



Joined: 03 Oct 2007
Posts: 155
Location: UK

PostPosted: Tue Oct 28, 2008 6:16 am    Post subject: Ternary Operator Documentation Reply with quote

It's not a major issue but it's caused me enough confusion to report this. The documentation of the use of the ternary operator is inconsistent as sometimes it is
Code:
x := foo > bar ? true : false ; correct use
and at other times is
Code:
x := foo > bar ? false : true ; incorrect use


It crops up from place to place in examples:
Quote:
The ternary operator is also a good candidate:
Code:
ProductIsAvailable := (Color = "Red")
    ? false  ; We don't have any red products, so don't bother calling the function.
    : ProductIsAvailableInColor(Product, Color)


though the description of the ternary operator itself is correct:
Quote:
For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3


Many thanks
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Oct 28, 2008 6:46 am    Post subject: Re: Ternary Operator Documentation Reply with quote

No, the examples you cite are correct.
Code:
ProductIsAvailable := (Color = "Red")
    ? false  ; We don't have any red products, so don't bother calling the function.
    : ProductIsAvailableInColor(Product, Color)

Explanation: if color=red (TRUE), return FALSE, else return TRUE. So after evaluation the 'if' will fail (FALSE) if color=red.
For good explanation of the Ternary operator see http://tinyurl.com/4ujg6q
Back to top
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Tue Oct 28, 2008 7:07 am    Post subject: Re: Ternary Operator Documentation Reply with quote

tuna wrote:
The documentation of the use of the ternary operator is inconsistent as sometimes it is
Code:
x := foo > bar ? true : false ; correct use
and at other times is
Code:
x := foo > bar ? false : true ; incorrect use


Both of these are perfectly valid examples, just with opposite results..
Back to top
View user's profile Send private message AIM Address
tuna



Joined: 03 Oct 2007
Posts: 155
Location: UK

PostPosted: Tue Oct 28, 2008 7:10 am    Post subject: Reply with quote

sorry - my bad - its getting to late for this... Very Happy
Back to top
View user's profile Send private message
derRaphael



Joined: 23 Nov 2007
Posts: 841
Location: ~/.

PostPosted: Tue Oct 28, 2008 9:05 pm    Post subject: Reply with quote

in case u want to use just true and false as direct assignments you can also use this ternary

Code:
x := foo > bar


greets
dR
_________________

    All scripts, unless otherwise noted, are hereby released under CC-BY
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group