Properties of junked script objects persist if referenced
Properties of junked script objects persist if referenced
- Subject: Properties of junked script objects persist if referenced
- From: Nigel Garvey <email@hidden>
- Date: Tue, 16 Jul 2002 23:52:21 +0100
Can anyone help me get my head round this? I feel I have all the clues,
but I can't put them together convincingly.
As is well known, a value that's pointed to by either a global or a
property when a script finishes is saved back into the script file. If
not, it's simply discarded.
One possible value class for a variable is a 'reference':
set myList to {1, 2, 3, 4, 5}
set myListRef to a reference to myList
--> myList of <<script>>
The reference here is to the variable myList, not to its list value. If
the value of myList later changes to "Hello", that's what'll comes back
when you check myListRef's 'contents'. Interestingly, myList needn't
actually exist - as long as you don't try to access myListRef's contents
until it does.
My confusion arises from the following. If I save this script and run it:
on fred()
script
property myList: {1, 2, 3, 4, 5}
end script
end fred
fred()
... the invisible result is of course <<script>>. As this is not then
assigned to a global or to a property, it doesn't get saved back into the
script file and the file's size and modification date remain unchanged.
From this, I deduce that myList is only a 'property' in the context of
the discarded script object.
But while fooling around with has's "list wrappers" (Re: Passing
*possible* variables to a handler), I came up with the following:
on fred()
script
property myList: {6, 7, 8, 9, 10}
end script
return a reference to the result's myList
end fred
fred()
the result's contents
--> {6, 7, 8, 9, 10}
Although the script object itself is essentially discarded at the exit
from the handler, it's still possible to access its property with a
reference. This might be explained by the fact that the script object
still exists in memory, even though there are no variables pointing at it.
Going on from there, I tried saving this and running it:
property savedRef : missing value
on fred()
script
property myString : "Hello"
end script
return a reference to the result's myString
end fred
if savedRef is missing value then
set savedRef to fred()
else
display dialog savedRef's contents
end if
On the first run, the only apparent result was of course that the script
file got bigger and its modification date was updated. On subsequent
runs, the script displayed the message "Hello".
The saved value of savedRef is just a *reference* to a property of a
script object. The script object itself isn't assigned to any variable at
all and so I'd expect it and its property to disappear when the main
script terminates (as in the previous script-file demo). Yet on
subsequent runs, it's possible to access the value of its referenced
property.
Just how much of what is saved back to the file in this case?
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.