MACSCRPT Archives

February 2009

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Deivy Marck Petrescu <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Fri, 6 Feb 2009 18:57:33 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (79 lines)
On Feb 6, 2009, at 5:48 AM, Nigel Garvey wrote:

> Ryan Wilcox wrote on Thu, 5 Feb 2009 21:40:20 -0500:
>
>> On Feb 5, 2009, at 6:03 PM, Deivy Marck Petrescu wrote:
>>> ... modifying a string and then creating a huge list.
>>> But still, the second is playing with a list from the outset.
>>> I believe a while ago Chris Nebel put a god explanation on why lists
>>> require more "work" in the Apple AppleScript list.
>>> If one does away with the need of manipulating a list but instead
>>> uses a reference to the list then the situation changes  
>>> dramatically:
>>>
>>> repeat 10000 times
>>> 	set end of (a reference to c) to "a"
>>> end repeat
>>> set t3 to (current date) - t2
>>
>>
>> EXCEPT the "reference to"  trick ONLY works in the (implicit or
>> explicit) run hander (because that's the only place you can  
>> explicitly
>> create a reference in AppleScript, which I mention in my article.
>> Well, unless you make c a property - then you can use it as a  
>> reference.
>
> A now-famous trick is to reference a property of a script object,  
> which
> works locally:
>
>  on myHandler()
>    script o -- o is local to myHandler.
>      property c: {}
>    end
>
>    repeat 10000 times
>      set end of o's c to "a" -- o's c instead of c of «script»
>    end repeat
>
>  end myHandler
>
>
> NG



Hello Nigel!

By the way, I mentioned the reference because I thought it was simpler.
Actually thank you Ryan for pointing out that for a list declared   
inside a handler the reference will not work.
I was not aware of that.
Actually, to be able to be referenced, I believe that c has to be  
declared inside a script and not a handler.
So, it is not the fact that "c" is declared in the run handler, but  
that "c" is a global property of the script.

Also, I just want to point out that  Nigel's script method works even  
if the script is defined outside the handler.
So
  -----
    script o -- o is local to myHandler.
      property c: {}
    end

on myHandler()
    repeat 10000 times
      set end of o's c to "a"
    end repeat

  end myHandler
-----
will work as well.



Deivy Petrescu
[log in to unmask]

ATOM RSS1 RSS2