Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- Subject: Re: (2 of 2) Application Scripting Question - Theoretical? (was Re: Technote 2106 is da Bomb)
- From: Nigel Garvey <email@hidden>
- Date: Wed, 14 Apr 2004 14:46:03 +0100
BJ Terry wrote on Tue, 13 Apr 2004 20:09:57 -0700:
>
Obviously, if you simply set a symbol to something, that symbol should
>
take on the meaning you were setting it to, so L would be {3, 4}. In
>
this case we already have a keyword which makes sense in this
>
situation, "contents". If someone asked me about the following:
>
>
set x to 1
>
set L to {a reference to x, 2}
>
set L's contents to {3, 4}
>
>
I would expect it to behave in a manner consistent with AppleScript's
>
normal behaviour, multiple simultaneous assignment.
AppleScript's normal behaviour is to error if you try to assign a value
to anything other than a variable or a writable property. L is a list.
L's contents is a list. You can't assign a value to a list. Therefore, an
error occurs when the code runs.
The point I was trying to get over to Michael earlier is that when you
write:
set {x, contents of y} to {3, 4}
... it's the compiler, not the compiled code, which recognises that you
want to assign the individual values in the right-hand list to the
individual variables or properties in the left-hand list. It then
generates code that will set each of those variables or properties in
turn.
set {x, y, z} to {3, 4}
--> Can't get item 3 of {3, 4}
This error is consistent with a failure in the third iteration of a loop
or in the third of three similar sections of code, suggesting that the
compiler generated code to perform three settings. This theory also holds
good with:
set {x, y, z} to {3, 4, 5, 6}
--> No error; three settings; item 4 of {3, 4, 5, 6} presumably ignored
set {x, y, z} to "abc"
--> x, y, & z set to the corresponding 'items' of "abc"
In all of these cases, the returned 'result' is the value of the object
after 'to'.
When compiling the line:
set L's contents to {3, 4}
... the compiler has no idea what L will be or what its contents will be.
The most reasonable assumption, given the language specification, is that
L will be a reference and that it's contents will be either another
variable or a property. The sensible and reasonable course in this case
is to generate code that will assign the single list value {3, 4} to
whatever variable or property 'L's contents' refers to when the code's
run. It's perfectly consistent and normal for AppleScript to generate an
error if 'L's contents' turn out to be neither a variable nor or a
property. The most likely explanations are either that something
unexpected has occurred during the earlier course of the script or, as
here, that the wrong syntax has been used in the source code.
What *is* strange is that 'set {1, 2, 3} to {4, 5, 6} doesn't error. I
currently have no theories about that.
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.