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:
Sun, 8 Feb 2009 11:19:30 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (94 lines)
On Feb 8, 2009, at 10:12 AM, Nigel Garvey wrote:

> Deivy Marck Petrescu wrote on Fri, 6 Feb 2009 18:57:33 -0500:
>
>> 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:
>
>>>>> If one does away with the need of manipulating a list but instead
>>>>> uses a reference to the list then the situation changes =20
>>>>> 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 =20
>>>> explicitly
>
>>> A now-famous trick is to reference a property of a script object,  
>>> =20
>>> 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 =ABscript=BB
>>>   end repeat
>>>
>>> end myHandler
>>>
>>>
>>> NG
>>
>>
>>
>> Hello Nigel!
>
> Hi, Deivy!  :)
>
>> By the way, I mentioned the reference because I thought it was  
>> simpler.
>
> I forgot to mention that your reference suggestion …
>
>  set end of (a reference to c) to "a"
>
> … can be simplified further to:
>
>  set end of my c to "a"
>
> This is quite a bit faster, as the reference to c is compiled directly
> into the script instead of being set up anew and plugged in each  
> time the
> line's executed.
>

You are absolutely right. I am creating a new reference every run,  
which is not smart.

> I suppose another point worth mentioning with regard to top-level
> properties, globals, and run-handler variables that their values at  
> the
> end of a run are saved back into the script file. If the values  
> include a
> list containing 10000 copies of the letter "a", it can cause a fair  
> bit
> of bloat! Persistent variables with values that aren't actually needed
> again can be set to something short like "" at the end of a script. I
> personally prefer to use locals instead as I get annoyed by changes to
> the scripts' modification dates! (And by the unnecessary backup  
> sizes caused.)
>
>
> NG

This is a good point, but it is important to remember that any  
variable declared at the script's top level is global, that is, has  
its value saved in the script after each run.
So, the script of the original poster would save a, b , i, etc.


Deivy Petrescu
[log in to unmask]

ATOM RSS1 RSS2