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

Home » Public Forums » archive » Re: brain twister
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
Re: brain twister [message #22797] Fri, 08 December 2000 15:02
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Todd Clements wrote:
>
> Paul van Delst <pvandelst@ncep.noaa.gov> wrote:
>
>>> Okay, enough ideology for one week.
>>
>> That's *almost* a pun. :o)
>
> Wow, I missed that one. Getting slow, I guess.
>
>>> ----- Example 2
>>> .comp
>>> function test2, x
>>> return, x
>>> end
>>>
>>> a = dindgen(5)
>>> (test2(a))[2] = -2
>>> print, a
>>
>> You're right...this is weird. If you do a help:
>>
>> IDL> help, test2(a)
>> A DOUBLE = Array[5]
>>
>> How come the result isn't
>>
>> <Expression> DOUBLE = Array[5]
>
> I wouldn't expect the result to be <Expression> becaues the result _is_ A,
> so I would expect IDL to tell me that the result is A. We pass in a by
> reference, return it, and so we should expect to get it back. I'm happy
> that IDL can keep track of the variable through all that mucking around...
> it makes sense to me.

Fair enough. I'm thinking in Fortran mode where there is no standard requirement for parameter
passing to be by value or by reference. I forgot IDL isn't like that.

After reading the online docs, you're absolutely correct that the result is "A" and not an
expression. The result does make sense. After much thought and reflection at least. :o)

paulv

--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.207, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
Re: brain twister [message #22800 is a reply to message #22797] Fri, 08 December 2000 13:10 Go to previous message
mole6e23 is currently offline  mole6e23
Messages: 31
Registered: December 1998
Member
Paul van Delst <pvandelst@ncep.noaa.gov> wrote:

>> Okay, enough ideology for one week.
>
> That's *almost* a pun. :o)

Wow, I missed that one. Getting slow, I guess.

>> ----- Example 2
>> .comp
>> function test2, x
>> return, x
>> end
>>
>> a = dindgen(5)
>> (test2(a))[2] = -2
>> print, a
>
> You're right...this is weird. If you do a help:
>
> IDL> help, test2(a)
> A DOUBLE = Array[5]
>
> How come the result isn't
>
> <Expression> DOUBLE = Array[5]

I wouldn't expect the result to be <Expression> becaues the result _is_ A,
so I would expect IDL to tell me that the result is A. We pass in a by
reference, return it, and so we should expect to get it back. I'm happy
that IDL can keep track of the variable through all that mucking around...
it makes sense to me.

Todd
Re: brain twister [message #22802 is a reply to message #22800] Fri, 08 December 2000 11:37 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Craig Markwardt wrote:
>
> Okay, enough ideology for one week.

That's *almost* a pun. :o)

>
> ----- Example 2
> .comp
> function test2, x
> return, x
> end
>
> a = dindgen(5)
> (test2(a))[2] = -2
> print, a

You're right...this is weird. If you do a help:

IDL> help, test2(a)
A DOUBLE = Array[5]

How come the result isn't

<Expression> DOUBLE = Array[5]

???


--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.207, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
Re: brain twister [message #22806 is a reply to message #22802] Fri, 08 December 2000 09:59 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Well, try this. I think it is doing exactly what you expect given that A
is passed by reference, no matter how bizarre it looks.

.comp
pro test1, x, y
x[2] = 10.
print, y
end

a = findgen(10)
print, a
test1, a, a

X and Y are "pointers" to the same array A.
Cheers,
Pavel
Re: brain twister [message #22808 is a reply to message #22806] Fri, 08 December 2000 08:58 Go to previous message
mole6e23 is currently offline  mole6e23
Messages: 31
Registered: December 1998
Member
craigmnet@cow.physics.wisc.edu wrote:

> Okay, enough ideology for one week. Here are some brain twisters for
> you. See if you can decide what the output should be without running
> it. In each example I give the commands to paste into the command
> line, ending with some main-level commands to enter.

I was able to guess number two, but I never would have guessed at number
one. I'm assuming this is some sort of memory saving device? I notice that
if you pass a,a+1 you get something different, which, after having seen
the results of example 1, you might be able to expect.

Look at the two following examples for another interesting behavior
(although not quite as interesting by any means!):

;; begin
.comp
pro test1, x, y, z
help, y, x, z
end

.comp
pro test2, y, x, z
help, z, y, z
end

a=dindgen(5)
test1,a,a,a
test2,a,a,a
;; end

That surprised me a little at first, but I guess it makes sense. You have
to do something with your variables in the program.

I think example two makes a lot of sense...you are passing the parameter
directly. If you can modify x within the function/procedure, why not
actually return x?

Neat examples, though!

Todd

>
> ----- Example 1
> .comp
> pro test1, x, y
> help, x, y
> end
>
> a = dindgen(5)
> test1, a, a
>
> ----- Example 2
> .comp
> function test2, x
> return, x
> end
>
> a = dindgen(5)
> (test2(a))[2] = -2
> print, a
>
> These were a bit of a surprise for me!
> Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: WNT environmental vars
Next Topic: IDLWAVE 4.6

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

Current Time: Wed Oct 08 13:47:39 PDT 2025

Total time taken to generate the page: 0.00674 seconds