Re: minimum function?
Re: minimum function?
- Subject: Re: minimum function?
- From: "Gary (Lists)" <email@hidden>
- Date: Wed, 06 Apr 2005 20:44:47 -0400
Some list history (and humor and excellent explanation, IMO)...
Simon Forster wrote [4/6/05 8:00 AM]:
> Why do you create a script object to hold the list of numbers? Why
> don't you access the list of number passed into the function directly?
> If it's a speed thing, can you explain a but further?
Simon, et. al. --
Below (at end) is a repeat of a similar question and Nigel's answer from
2003. Paul B., Arthur K. and others have also offered explanations of this
speed method, as well as additional examples and uses (and humor), over the
years.
c.f.:
11/28/2003; Paul Berkowitz; "Re: speed of Applescript application"
[@ email@hidden]
10/20/2003; Nigel Garvey; "Re: Sorting file lists"; also contains
modifications to 'QuickSort' by Arthur Knapp
[@ AS-Users List]
5/11/2004; Paul Berkowitz; "Re: Speedy processing of lists";
[@ email@hidden]
> Right. You can also use the Garvey variant ('my) without a script object at
> the top level of a script but not in a handler unless the variable has been
> declared a global variable. The Serge method (or the Garvey use inside a
> script object, as above, which I've not seen before) can be used only in a
> handler - otherwise you get a "mylist is not defined" error when you try to
> compile the script. They're equivalent methods with the same speed. So I use
> the Garvey 'my' at top level, and the Serge method in handlers.
and (one of my favorites)...
5/11/2004; Aruthur Knapp; "Re: Speedy processing of lists";
[@ email@hidden]
>> From: "John A.M. Darnell" <email@hidden>
>>
>> Are "serge" and "garvey" intrinsic commands to Applescript?
And Arthur's very funny reply:
> ;-)
>
> The Nigel Garvey command (version 1.0) was first introduced
> in the localized Stratford-upon-Avon version of AppleScript,
> as a part of the Standard RSC commands. Underpowered and buggy,
> he was subsequently overhauled and reintroduced as iNigel, and
> later as Nigel X. (Forget the rumors, there was never going to
> be a Copland Nigel Garvey). His new Aqua interface is ugly and
> toy-like, but he still retains his Classic demeanor.
>
> The Serge Belleudy-d'Espinose command is only available with
> the AppleScript French dialect, sorry.
>
> ;-)
>
> P.S. I am desperately waiting for someone to name something
> after me.... ;-)
>
> Arthur Knapp
Hmmm: "knapp time" ?
Ciao,
Gary
Here is a complete answer...
==============================================
Steve Cunningham wrote [6/8/2003 05:18 AM]:
>>What is "the Serge method"?
Nigel Garvey wrote [6/8/2003 7:10:35 PM]:
>The Serge method is named after Serge Belleudy-d'Espinose, who
>popularised it a year or two ago. He noticed that, in a handler, if a
>list was made a property of a script object, access to it was very much
>faster than otherwise:
>
> on myHandler(longList)
>
> script o
> property spLongList:longList
> end script
>
> -- Slow
> repeat with i from 1 to 4000
> item i of longList
> end repeat
>
> -- Fast
> repeat with i from 1 to 4000
> item i of o's spLongList
> end repeat
>
> end myHandler
>
>Research suggests that the second loop is faster because it refers to the
>list by a reference expression - "o's spLongList" (two words) - rather
>than just a variable name. According to Chris Nebel, this referential
>approach sidesteps certain time-consuming safety checks that are built
>into list accesses. The last I heard, some soul-searching was going on at
>Apple about whether these checks are really necessary.
>
>The idea then is to engineer a situation where you can use a reference
>expression to refer to the list. In your script, the line of code that
>refers to the list is inside a script object where the list variable has
>global scope. You *could* make another script object within the script
>object and refer to it that way, but here you may as well just use "my".
>In your script, "my columns" equates to "columns of script matrix".
>
>One important thing to remember is that the speed gain only comes about
>when you're accessing numbered positions in the list - eg. "item i of o's
>longList", "items 1 thru 7 of o's longList" - or when you're *getting*
>its "rest", "end", or "beginning". With expressions such as "set end of",
>"set beginning of", "is in", or "contains", using a straight variable is
>just as fast as using a reference and is usually a tad faster.
>>If you can point me to a reference that explains it, I'd appreciate it.
>I don't know of any, I'm afraid, apart from previous discussions on this
>list or MACSCRPT. The AppleScript Language Guide briefly mentions that
>the use of reference variables instead of the original list variables can
>things up, but doesn't say why:
>
> set myList to {<- 4000 items ->} -- don't try compiling this!
> set listRef to a reference to myList
> repeat with i from 1 to 4000
> item i of listRef
> end
>
>This only works at the top level of a script, not in a handler. The value
>of listRef is the reference "myList of <<script>>". Instead of listRef,
>you could use "my myList", which also means "myList of <<script>>". The
>difference is that with "my", the reference is compiled directly into the
>script instead of being held in a variable, and gives faster results.
>
>NG
--
//END//
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden