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

Home » Public Forums » archive » temporary() problem
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
temporary() problem [message #86024] Tue, 24 September 2013 13:25 Go to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
Hi,

I'm not sure I understand why the variable 'a' below gets undefined after calling a procedure using temporary():

IDL> a='a, b, c'
IDL> help, a
A STRING = 'a, b, c'
IDL> .run "test.pro"
% Compiled module: TEST.
IDL> test, a
IDL> help, a
A UNDEFINED = <Undefined>


The contents of test.pro:

PRO TEST, str
ostr=strsplit(temporary(str), ', ', /extract)
END


Why is temporary() messing with the top level environment?


Seb
Re: temporary() problem [message #86025 is a reply to message #86024] Tue, 24 September 2013 13:32 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
spluque@gmail.com writes:

> I'm not sure I understand why the variable 'a' below gets undefined after calling a procedure using temporary():
>
> IDL> a='a, b, c'
> IDL> help, a
> A STRING = 'a, b, c'
> IDL> .run "test.pro"
> % Compiled module: TEST.
> IDL> test, a
> IDL> help, a
> A UNDEFINED = <Undefined>
>
>
> The contents of test.pro:
>
> PRO TEST, str
> ostr=strsplit(temporary(str), ', ', /extract)
> END
>
>
> Why is temporary() messing with the top level environment?

Because variables are passed by reference in IDL, not by value (copied
into the procedure). In this case, you are working with the variable str
itself, not a copy of the variable.

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: temporary() problem [message #86026 is a reply to message #86025] Tue, 24 September 2013 14:29 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/24/13 16:32, David Fanning wrote:
> spluque@gmail.com writes:
>
>> I'm not sure I understand why the variable 'a' below gets undefined after calling a procedure using temporary():
>>
>> IDL> a='a, b, c'
>> IDL> help, a
>> A STRING = 'a, b, c'
>> IDL> .run "test.pro"
>> % Compiled module: TEST.
>> IDL> test, a
>> IDL> help, a
>> A UNDEFINED = <Undefined>
>>
>>
>> The contents of test.pro:
>>
>> PRO TEST, str
>> ostr=strsplit(temporary(str), ', ', /extract)
>> END
>>
>>
>> Why is temporary() messing with the top level environment?
>
> Because variables are passed by reference in IDL, not by value (copied
> into the procedure). In this case, you are working with the variable str
> itself, not a copy of the variable.

I would go with the explanation that temporary() is "messing" with the
top level environment because that's what the programmer wrote it to do.

"Why is the computer doing what I told it to do, not what I want it to do?"

:o)


For the OP, try this for some obfuscatory fun:

IDL> a=['qwerty','a,b,c']
IDL> help, a
A STRING = Array[2]
IDL> print, a
qwerty a,b,c
IDL> .run "test.pro"
% Compiled module: TEST.
IDL> test, a[1]
IDL> print, a
Re: temporary() problem [message #86027 is a reply to message #86026] Tue, 24 September 2013 14:39 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:

> I would go with the explanation that temporary() is "messing" with the
> top level environment because that's what the programmer wrote it to do.
>
> "Why is the computer doing what I told it to do, not what I want it to do?"

This comes later in the syllabus, when we talk about "programming
philosophy, prayer, and metaphysics." ;-)

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: temporary() problem [message #86028 is a reply to message #86027] Tue, 24 September 2013 15:43 Go to previous message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
Thanks to both of you! Clearly, I wasn't paying attention to the book section on argument passing mechanism. Now I've learnt not to use temporary() directly on arguments!

Cheers,
Seb


On Tuesday, September 24, 2013 4:39:39 PM UTC-5, David Fanning wrote:
> Paul van Delst writes:
>
>
>
>> I would go with the explanation that temporary() is "messing" with the
>
>> top level environment because that's what the programmer wrote it to do.
>
>>
>
>> "Why is the computer doing what I told it to do, not what I want it to do?"
>
>
>
> This comes later in the syllabus, when we talk about "programming
>
> philosophy, prayer, and metaphysics." ;-)
>
>
>
> 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: Reading part of a netcdf file?
Next Topic: A newbie question regarding 3D plotting

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

Current Time: Wed Oct 08 13:45:51 PDT 2025

Total time taken to generate the page: 0.00528 seconds