AutoHotkey Community

It is currently May 26th, 2012, 11:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: October 28th, 2008, 7:16 am 
Offline

Joined: October 3rd, 2007, 9:32 pm
Posts: 157
Location: UK
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 28th, 2008, 7:46 am 
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


Report this post
Top
  
Reply with quote  
PostPosted: October 28th, 2008, 8:07 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 28th, 2008, 8:10 am 
Offline

Joined: October 3rd, 2007, 9:32 pm
Posts: 157
Location: UK
sorry - my bad - its getting to late for this... :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 28th, 2008, 10:05 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
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

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group