Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
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
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
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
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