Re: a question about accessing list items through a reference
Re: a question about accessing list items through a reference
- Subject: Re: a question about accessing list items through a reference
- From: Tetsuro KURITA <email@hidden>
- Date: Wed, 6 Jun 2007 14:16:53 +0900
Thanks for you reply.
> I cannot give you the technical reasons for my suggestion that follows but I had a related problem back when AppleScript was given an overhaul going into 10.3 Panther. I had used a lot of the 'my' references in my scripts and suddenly my scripts didn't execute well or at all.
In my memory, 'the' does not have actual meaning. 'the' can be used to
obtain English like looking of codes. What you did is same to just removing
'my'.
On the other hand, 'my' have actual meaning that indicating current script.
I have used 'my' in my examples. But my problem is not restricted in the
case using 'my'. We can replace 'my' with other script object as follows.
script AScript
property a_list : {1, 2}
end script
repeat with ref_to_item in a_list of AScript
set contents of ref_to_item to 3 -- error of number -10006
end repeat
What I wanted to say is that specifying script object which have the list
causes a problem.
> This was resolved by using 'the' instead of 'my' to get a sub-routine to refer to a global property such as you have in your example. Using 'my' seems to be reserved for referring to another sub-routine outside of the current routine:
>
> property a_list : {1, 2}
>
> my setItem()
>
> on setItem()
> set a_ref to a reference to item 1 of the a_list
> set contents of a_ref to 3
> end
You can remove 'my' from above script.
I think "Using 'my' seems to be reserved for referring to another sub-routine outside of the current routine:" is not correct understanding.
>
>
> On May 30, 2007, at 9:41 PM, Tetsuro KURITA wrote:
>
>> I could resolve my problem by myself.I looks that nobody is interested in
>> myproblem. But I will introduce my experience, because someone will meet
>> sameproblem. Also even now I have unsolved questions. Therefore I hope
>> authority's comments.
>>
>> A reference to an item of a list may usually appear in a loop of "repeat with ~ in ~" statement as follows.
>>
>> (* Script A *)
>> property a_list : {1, 2}
>> repeat with ref_to_item in a_list
>> set contents of ref_to_item to 3
>> end repeat
>>
>> Above script works well. But very slow. As well known, to accelerate
>> loop,items of AppleScirpt's list must be accessed through a reference to a
>> list or script object as follows.
>>
>> (* Script B *)
>> property a_list : {1, 2}
>> repeat with ref_to_item in my a_list
>> set contents of ref_to_item to 3 -- error of number -10006
>> end repeat
>>
>> But this script does not work. Someone says I can drop "my" before "a_list".
>> But we need "my" in the point of view of the performance, and it should be
>> considered that the list is in the other script object in some cases.
>>
>> Accidentally I found the following scripts works well.
>>
>> (* Script C *)
>> property a_list : {1, 2}
>> repeat with ref_to_item in (a reference to my a_list)
>> set contents of ref_to_item to 3
>> end repeat
>>
>> I could have obtained what I wanted. But I could not understood what happen.
>> Why does not "Script B" works ?
>> Why does "Script C" works ?
>>
>>> I found a strange behavior when accessing list items.
>>>
>>> The following code works.
>>>
>>> property a_list : {1, 2}
>>> set a_ref to a reference to item 1 of a_list
>>> set contents of a_ref to 3
>>>
>>> But following code does not works with error of number -10006.
>>>
>>> property a_list : {1, 2}
>>> set a_ref to a reference to item 1 of my a_list
>>> set contents of a_ref to 3
>>>
>>> Is it a bug ?
>>
>>
>> =======================================================
>> Tetsuro KURITA
>> E-mail: email@hidden
>> http://homepage.mac.com/tkurita/scriptfactory/en/
>> =======================================================
>>
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> AppleScript-Users mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> Archives: http://lists.apple.com/archives/applescript-users
>>
>> This email sent to email@hidden
>
> --
> ForNow
> DigitEL
>
> <pastedGraphic.tiff>
>
>
=======================================================
Tetsuro KURITA
E-mail: email@hidden
=======================================================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden