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:
Nigel Garvey <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Sun, 8 Feb 2009 15:12:36 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (1 lines)
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.



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

ATOM RSS1 RSS2