comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » logical_true vs nothing in an if statment
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
logical_true vs nothing in an if statment [message #85926] Wed, 18 September 2013 12:44 Go to next message
munka is currently offline  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 Go to previous messageGo to next message
David Fanning is currently offline  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 #85928 is a reply to message #85926] Wed, 18 September 2013 12:53 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
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
>
Re: logical_true vs nothing in an if statment [message #85929 is a reply to message #85928] Wed, 18 September 2013 13:07 Go to previous messageGo to next message
munka is currently offline  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 Go to previous messageGo to next message
munka is currently offline  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 Go to previous messageGo to next message
Michael Galloy is currently offline  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 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  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 #85933 is a reply to message #85932] Wed, 18 September 2013 15:06 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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.")
Re: logical_true vs nothing in an if statment [message #85934 is a reply to message #85933] Wed, 18 September 2013 15:44 Go to previous messageGo to next message
billfreeman44 is currently offline  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 Go to previous messageGo to next message
wlandsman is currently offline  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?
Re: logical_true vs nothing in an if statment [message #86014 is a reply to message #85937] Tue, 24 September 2013 07:48 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 09/19/13 16:22, wlandsman wrote:
> 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

Ha.

I love the phrase:
'burned too many times before on the definition of "truth" '

Makes me feel sort-of (but not really) sympathetic towards lawyers.
Re: logical_true vs nothing in an if statment [message #86015 is a reply to message #86014] Tue, 24 September 2013 07:51 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> I love the phrase:
> 'burned too many times before on the definition of "truth" '

I thought this was the opening line to the novel Wayne's writing!

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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: idl: turn string value into variable name part2
Next Topic: Reading large files with restore

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:43:50 PDT 2025

Total time taken to generate the page: 0.00613 seconds