Many thanks to everyone who responded. It was all very helpful, and Tab's write-up was especially educating; you can tell he's an author and a teacher :-)

Slava

At 05:03 AM 2/7/03 -0500, you wrote:

They're not different. They do behave the same.

Test =[#a : ["a", "b"]]
Test1 = Test[#a]
put Test1
-- ["a", "b"]

At this stage, Test1 points to the list ["a", "b"]. That particular list exists somewhere in the ether, and is referenced by two objects - one is 'Test' (where it is part of the property list) and the other is 'Test1' (to whom it is directly assigned). If either Test or Test1 manipulated the list, the other would reflect the change.

Then, however you do:
Test1 = ["x", "y"]

and express surprise that Test itself did not change. However, if you think about what you did, you did not change the list. Instead, you assigned a BRAND NEW LIST to Test 1. There are now two lists in existence - ["a", "b"], referenced only by 'Test' in the property list, and a second list ["x", "y"], referenced only by 'Test1'.

As others have noted, if you want Test1 to have a copy of the original, you can use the duplicate() function. On the other hand, if you want to manipulate the original list and replace ["a", "b"] with ["x", "y"] then you'll need to manipulate the CONTENTS of the list without changing the list itself, as in:

Test =[#a : ["a", "b"]]
Test1 = Test[#a]
put Test1
-- ["a", "b"]

Test1[1] ="x"
Test1[2] ="y"
put Test1
-- ["x", "y"]
put Test
-- [#a: ["x", "y"]]

Hope this helps

- Tab

At 12:19 AM 2/7/03, Slava paperno wrote:
A Lingo puzzle (at least for me):

The Number 1 sequence, below, indicates that when a variable is assigned a value that is taken from a property list, the assignment is done by value; the original list is not affected, when you change the value of the new variable.

The Number 2 sequence--using deleteProp()--indicates the reverse, i.e. that the new variable becomes a pointer to the list, and changing it in fact changes the original list.

Number 1:
Test=[#a : ["a", "b"]]
Test1 = Test[#a]
put Test1
-- ["a", "b"]
Test1 = ["x", "y"]
put Test
-- [#a: ["a", "b"]]

Number 2:
Test=[#a : ["a", "b"]]
Test1 = Test[#a]
put Test1
-- ["a", "b"]
Test1.deleteProp(1)
put Test1
-- ["b"]
put Test
-- [#a: ["b"]]

Questions:
1) Why the different behavior? How is it useful?
2) I want to delete an item from my Test1 w/o affecting the original list Test. How?

Thanks for any tips!

Slava
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/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!]


Reply via email to