assign by reference (arrays)?
Michael D Mays
michael at GreppyDreppies.com
Fri Mar 22 07:56:01 EST 2002
Rob Cozens of rcozens at pon.net wrote the following on 3/21/02 9:11 AM
> Looking at it another way, one might say all inline variable
> assignments ARE by reference: "put x into y" replaces the value of
> "y", not a copy of "y".
If you could say
put "cat" into x
put a reference of x into y
put "dog" into y
put x&&y
the message box would show
dog dog
When you say
put "cat" into x
put x into y
put "dog" into y
put x&&y
the message box would show
cat dog
and you are coping the value of x and creating a new variable y with a copy
of the value of x or you are over writing the exiting value of the variable
y with a copy of the value of x.
A variable name is a sort of pointer to the actual location in memory where
the value of the variable resides. When you create a reference of (to) that
variable you don't create another location in memory for the value of the
variable, you just create another pointer which points to that one location
in memory.
variable Memory 'value'
x -----> 187920 [cat]
/
y ----/
When you say put x into y
x -----> 187920 [cat]
y -----> 563760 [cat]
If y is a reference to x, any change to x is a change to y and vice versa:
they both represent the same location in memory.
irrc:)
michael
More information about the use-livecode
mailing list