A combination of two things. First, any variables created in the message
window are global. In your case, that means that the list persists.
Second, lists are passed by reference. This can be helpful sometimes,
though I think generally it just trips people up. You could do:
a=[1,1]
b=a
b[1]=4
put b
-- [4, 1]
put a
-- [4, 1]
Because when you do a=b you assign the pointer, not the list itself. Same
thing happens in your handler.
To avoid it, you would instead do:
a=duplicate(b)
So, you're operating on an existing list whose value is already [1,1].
In fact, what you got is exactly what you asked for. Your function added 1
to whatever was in there. So you got 2's.
- Tab
At 12:40 PM 11/1/00 +0100, Szymon Drejewicz wrote:
>Hello,
>
>Is it new BUG?:
>
>This is a nice, simple, useless function:
>
>on myFunction a
> a = a + 1
>end
>
>check in Message Window:
>---------------------------------
>b = 1
>myFunction(b)
>put b
>-- 1
>---------------------------------
>OK. WORKS GOOD. BUT:
>
>on myFunctionForLists v
> v[1] = v[1] + 1
> v[2] = v[2] + 1
>end
>
>let's see how it's working (in Message Window):
>---------------------------------
>w = [1,1]
>myFunctionForLists(w)
>put w
>-- [2,2]
>---------------------------------
>WHY !? SHOULD BE
>-- [1,1]
>
>Can you explain that?
>
>Szymon Drejewicz
>
>[To remove yourself from this list, or to change to digest mode, go to
>http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
>email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
>Lingo-L is for learning and helping with programming Lingo. Thanks!]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]