Re: Declaration of variables in IDL [message #26884 is a reply to message #26881] |
Wed, 03 October 2001 09:08   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Todd Clements (mole6e23@hotmail.com) writes:
> However, you can get *some* type of variable checking during run time by
> using structures.
>
> a = {b: fltarr(10), c: 0L}
>
> a.b = 5 ;; this works, setting all elements of b to 5
> a.b = 'hi' ;; this DOESN'T work, yielding a type conversion error
> a.b = findgen(7) ;; this does work, yielding 0,1,2,3,4,5,6,0,0,0
> a.c = [2,3] ;; this DOESN'T work since C is a scalar
>
> Even though you can get some rudimentary type checking this way, I think
> it can cause more problems than it is worth...
With the exception of strings, I don't think I
would call this "type" checking at all. More
like "space" checking, since IDL doesn't care
what you stuff into a structure field as long
as it fits into the memory set aside for it.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|