[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: brain twister



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