Re: By nice to the Windows user come to AppleScript please :-)
Re: By nice to the Windows user come to AppleScript please :-)
- Subject: Re: By nice to the Windows user come to AppleScript please :-)
- From: Andy Satori <email@hidden>
- Date: Fri, 11 Jan 2002 13:16:24 -0500
On 1/11/02 5:52 AM, "has" <email@hidden> wrote:
>
Paul Berkowitz wrote:
>
>
> repeat with someItem in theItems
>
>
>
> end repeat
>
>
>
>
>
> Frequently, and usually when the list consists not of application objects
>
> but of strings or numbers - just a pre AppleScript list - you run into
>
> problems because the item is not evaluated. (It is 'item x of {item 1 of
>
> someItems, item 2 of someItems, ...}.)
>
>
Yup. As you indicate, what you actually get with the "repeat with x in y"
>
construct is actually a reference to an object in y, *not* the object
>
itself. This is stated in the ASLG, btw, though not made obvious enough
>
imho.
>
>
It's one of those counter-intuitive 'gotchas' that can catch out novices
>
all too easily, many of whom are likely to use repeat loops long before
>
they learn what a reference is. (I know it caught me...:p)
>
>
The problem seems compounded as follows:
>
>
repeat with x in {1, 2, 3}
>
x
>
end repeat
Well, this would make sense in truth.
Think about it this way, in this syntax, you are returning a pointer to an
object rather than moving the value (the entire object) around in memory,
I'll just give you a pointer to it. Once you do the set, you are confirming
you do indeed want the whole shooting match to manipulate. Now in a
traditional programming environment like say C++, you'd dereference the
pointer or use the indirection operator theItem->method(); whereas in a
script environment, you really want to abstract away from the 'pointer'
methodology for ease of use. In Visual Basic scripting, this is resolved by
always passing back the object. It appears to me (a relative newbie to AS)
that this is an example of AS simply using the pointer mechanism internally.
It would seem to make sense to me.
Andy
>
--> item 3 of {1, 2, 3} -- a reference, yes?
>
>
repeat with x in {1, 2, 3}
>
x's class
>
end repeat
>
--> integer -- except it swears its just an integer... hmm
>
>
Perhaps there's a good reason for this behaviour, but I'm not sure what it
>
must be. (Unfortunately, I suspect this is just the sort of thing that
>
gives AS a reputation for being quirky and unpredictable.:/)
>
>
has
>
_______________________________________________
>
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.