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

Home » Public Forums » archive » Re: string definition question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: string definition question [message #33606 is a reply to message #33605] Tue, 14 January 2003 10:45 Go to previous messageGo to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Paul van Delst <paul.vandelst@noaa.gov> writes:

> mwvogel wrote:
>>
>> As my news server refuses my post, I'll paste it here :-)
>>
>> ///////////////////
>> I would try KEYWORD_PRESENT; with A defined as 'IDL', B as '' and C
>> undefined I get the following :
>> IDL> A = 'IDL' & B = '' & PRINT, KEYWORD_SET(A), KEYWORD_SET(B),
>> KEYWORD_SET(C)
>>
>> 1 0 0
>>
>> I guess that works in routines too.


I've always been disappointed that the KEYWORD_SET() routine does not follow
the same logic as the rest of IDL for deciding whether something is true or
false. According to the definition of true and false in the documentation

Definition of True and False

The condition of the IF statement can be any scalar expression. The
definition of true and false for the different data types is as
follows:

* Byte, integer, and long: odd integers are true, even integers are
false.

* Floating-Point, double-precision floating-point, and complex:
non-zero values are true, zero values are false. The imaginary part of
complex numbers is ignored.

* String: any string with a nonzero length is true, null strings are
false.

However, the KEYWORD_SET() documentation simply says

The KEYWORD_SET function returns a nonzero value if Expression is
defined and nonzero or an array, otherwise zero is returned. This
function is especially useful in user-written procedures and functions
that process keywords that are interpreted as being either true
(keyword is present and nonzero) or false (keyword was not used, or was
set to zero).

In other words, KEYWORD_SET() treats integer and floating point equally, while
they're treated differently in conditional statements. I've always found that
troublesome. On the other hand, the treatment of strings is consistent between
the two, although it's undocumented for KEYWORD_SET().

William Thompson
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: string definition question
Next Topic: Re: 2-D Density Plots

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

Current Time: Wed Oct 08 19:22:15 PDT 2025

Total time taken to generate the page: 0.00355 seconds