logical_true vs nothing in an if statment [message #85926] |
Wed, 18 September 2013 12:44  |
munka
Messages: 36 Registered: December 2009
|
Member |
|
|
Why is the behavior of the 'if' statement in idl like this? I was under the impression putting nothing there is equivalent to the logical_true() statment???!
IDL> for i=0,10 do if i then print,'true' else print,'false'
false
true
false
true
false
true
false
true
false
true
false
IDL> for i=0,10 do if logical_true(i) then print,'true' else print,'false'
false
true
true
true
true
true
true
true
true
true
true
|
|
|
Re: logical_true vs nothing in an if statment [message #85927 is a reply to message #85926] |
Wed, 18 September 2013 12:48   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
mynameismunka@gmail.com writes:
>
> Why is the behavior of the 'if' statement in idl like this? I was under the impression putting nothing there is equivalent to the logical_true() statment???!
>
>
>
> IDL> for i=0,10 do if i then print,'true' else print,'false'
> false
> true
> false
> true
> false
> true
> false
> true
> false
> true
> false
> IDL> for i=0,10 do if logical_true(i) then print,'true' else print,'false'
> false
> true
> true
> true
> true
> true
> true
> true
> true
> true
> true
Why? I think you have the wrong newsgroup. You want
comp.lang.metaphysical. ;-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|
Re: logical_true vs nothing in an if statment [message #85929 is a reply to message #85928] |
Wed, 18 September 2013 13:07   |
munka
Messages: 36 Registered: December 2009
|
Member |
|
|
On Wednesday, September 18, 2013 12:53:44 PM UTC-7, Paul van Delst wrote:
> See:
>
>
>
> http://www.exelisvis.com/docs/Definition_of_True_and_F.html
>
>
>
> Your "if i then..." example is well documented (if a little strange)
>
> behaviour.
>
>
>
> On 09/18/13 15:44, mynameismunka@gmail.com wrote:
>
>> Why is the behavior of the 'if' statement in idl like this? I
>
>> was under the impression putting nothing there is equivalent to
>
>> the logical_true() statment???!
>
>>
>
>>
>
>>
>
>> IDL> for i=0,10 do if i then print,'true' else print,'false'
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> IDL> for i=0,10 do if logical_true(i) then print,'true' else print,'false'
>
>> false
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>>
Thanks for the help.
|
|
|
Re: logical_true vs nothing in an if statment [message #85930 is a reply to message #85927] |
Wed, 18 September 2013 13:17   |
munka
Messages: 36 Registered: December 2009
|
Member |
|
|
On Wednesday, September 18, 2013 12:48:36 PM UTC-7, David Fanning wrote:
> mynameismunka@gmail.com writes:
>
>
>
>>
>
>> Why is the behavior of the 'if' statement in idl like this? I was under the impression putting nothing there is equivalent to the logical_true() statment???!
>
>>
>
>>
>
>>
>
>> IDL> for i=0,10 do if i then print,'true' else print,'false'
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> true
>
>> false
>
>> IDL> for i=0,10 do if logical_true(i) then print,'true' else print,'false'
>
>> false
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>> true
>
>
>
> Why? I think you have the wrong newsgroup. You want
>
> comp.lang.metaphysical. ;-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Too bad it doesn't exist. There could be some interesting discussions :)
|
|
|
Re: logical_true vs nothing in an if statment [message #85931 is a reply to message #85929] |
Wed, 18 September 2013 13:22   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 9/18/13 2:07 PM, mynameismunka@gmail.com wrote:
> On Wednesday, September 18, 2013 12:53:44 PM UTC-7, Paul van Delst wrote:
>> See:
>>
>>
>>
>> http://www.exelisvis.com/docs/Definition_of_True_and_F.html
>>
>>
>>
>> Your "if i then..." example is well documented (if a little strange)
>>
>> behaviour.
>>
>>
>>
>> On 09/18/13 15:44, mynameismunka@gmail.com wrote:
>>
>>> Why is the behavior of the 'if' statement in idl like this? I
>>
>>> was under the impression putting nothing there is equivalent to
>>
>>> the logical_true() statment???!
>>
>>>
>>
>>>
>>
>>>
>>
>>> IDL> for i=0,10 do if i then print,'true' else print,'false'
>>
>>> false
>>
>>> true
>>
>>> false
>>
>>> true
>>
>>> false
>>
>>> true
>>
>>> false
>>
>>> true
>>
>>> false
>>
>>> true
>>
>>> false
>>
>>> IDL> for i=0,10 do if logical_true(i) then print,'true' else print,'false'
>>
>>> false
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>> true
>>
>>>
>
> Thanks for the help.
>
But, you can change this behavior in selected routines with the
logical_predicate compile option:
IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
false
true
false
true
false
true
false
true
false
true
false
IDL> compile_opt logical_predicate
IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
false
true
true
true
true
true
true
true
true
true
true
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
Re: logical_true vs nothing in an if statment [message #85932 is a reply to message #85931] |
Wed, 18 September 2013 14:37   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
On 09/18/13 16:22, Michael Galloy wrote:
>
> But, you can change this behavior in selected routines with the
> logical_predicate compile option:
>
> IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
> false
> true
> false
...etc...
> IDL> compile_opt logical_predicate
> IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
> false
> true
> true
...etc...
True (pun intended :o), and the OP should make sure the option is put in
the procedure/function in question, not an IDL startup file!
Also, what if someone writes code based on the false/true ping-pong
behaviour, and then gives the code to someone else that DOES have the
logical_predicate option set in a startup file?
Would hilarity ensue?
|
|
|
|
Re: logical_true vs nothing in an if statment [message #85934 is a reply to message #85933] |
Wed, 18 September 2013 15:44   |
billfreeman44
Messages: 1 Registered: September 2013
|
Junior Member |
|
|
On Wednesday, September 18, 2013 3:06:49 PM UTC-7, David Fanning wrote:
> Paul van Delst writes:
>
>
>
>> Also, what if someone writes code based on the false/true ping-pong
>
>> behaviour, and then gives the code to someone else that DOES have the
>
>> logical_predicate option set in a startup file?
>
>>
>
>> Would hilarity ensue?
>
>
>
> Yes, but only for main-level programs. :-)
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
I wonder how long it would take me to notice if someone slipped in the logical_predicate option into my startup file.
|
|
|
Re: logical_true vs nothing in an if statment [message #85937 is a reply to message #85932] |
Thu, 19 September 2013 13:22   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
I work with an IDL programmer who uses LOGICAL_TRUE *everywhere* including statements like
if LOGICAL_TRUE(Keyword_set(flag)) then setflag,...
He said he has been burned too many times before on the definition of "truth", so he always uses LOGICAL_TRUE() even in cases where it is unnecessary, such as when the variable can only take on the values 0 and 1.
His code drives me crazy... --Wayne
On Wednesday, September 18, 2013 5:37:04 PM UTC-4, Paul van Delst wrote:
> On 09/18/13 16:22, Michael Galloy wrote:
>
>>
>
>> But, you can change this behavior in selected routines with the
>
>> logical_predicate compile option:
>
>>
>
>> IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
>
>> false
>
>> true
>
>> false
>
> ...etc...
>
>> IDL> compile_opt logical_predicate
>
>> IDL> for i = 0, 10 do if i then print, 'true' else print, 'false'
>
>> false
>
>> true
>
>> true
>
> ...etc...
>
>
>
> True (pun intended :o), and the OP should make sure the option is put in
>
> the procedure/function in question, not an IDL startup file!
>
>
>
> Also, what if someone writes code based on the false/true ping-pong
>
> behaviour, and then gives the code to someone else that DOES have the
>
> logical_predicate option set in a startup file?
>
>
>
> Would hilarity ensue?
|
|
|
|
|