Yes. I can explain that.
It's not a bug, it's a feature.
the integer variables you use below are local.
> on myFunction a
> a = a + 1
> end
myFunction just adds 1 to the parameter sent in, and then does nothing
to it.
so if b = 1 and you send it through myFunction, b will still = 1,
because it's a separate local variable in the method. (by the way, it's
not a function, because it doesn't return anything. if you returned the
value of a, it would be a function, and the b that you send in would
return as 2
> on myFunction a
> a = a + 1
> return a
> end
b = 1
b = myFunction(b)
put b
-- 2
However, lists are a different matter. When you pass in a list as a
parameter, you are not passing in a separate local variable, the way you
would be if it were an integer. What you're passing in is a pointer to
the original list. So if you change the list, even if you don't return
it, it changes the original list.
you're passing in [1, 2] as w, and you're changing that same list in
myFunctionForLists. So even though you don't return the changed list,
the original list, w, is still changed.
You can use this to your advantage, or, if you want to decouple the
lists, and make them act like the integer, just duplicate the list when
it comes in:
w = duplicate(w)
and then it's a new list, same value as the old, but changes to the new
list do not change the old list.
clear?
--bhakti
>
> 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!]
--
R. Bhakti Klein
Lingo Programmer, Scientific Learning
http://www.ScientificLearning.com
http://www.BrainConnection.com
**
Baritone, Wicki6
http://www.wicki6.com
***
"On Earth, you can only do little things;
but you can do them with a lot of Love."
-- Mother Theresa
[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!]