• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Please Pass the Handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Please Pass the Handler


  • Subject: Re: Please Pass the Handler
  • From: email@hidden (Michael Sullivan)
  • Date: Fri, 11 Jan 2002 17:58:34 -0500
  • Organization: Business Card Express

> In some programming languages, you can pass a handler, (function or
> subroutine), to another handler, so that the passed handler can
> provide custom functionality. A typical example would be JavaScript's
> sort() method of arrays, where you pass a comparison function that
> tells sort() how to compare any two items in the array.

You are my alter-ego.

I was just thinking about this myself the last few days.

In response to David Wadson's issue about odd filename sorting, my
intention (because I actually have similar issues that will come
eventually in my own workflow scripting) was to modify Serge's qsort
algorithm to take a comparison handler.

I had the exact problem you did and found the workaround where you pass
a script object instead of directly passing a handler. That got it to
work in the simple test situation, but in my actual program, if I tried
to sort a list longer than a few items, I ended up with a stack
overflow.

I fear that AS doesn't like passing too many levels deep of script
objects and unfortunately the simple quicksort implementation is
recursive, potentially requiring many levels of depth. I didn't follow
through the debugging yet to see if I've done something stupid or if it
really is going to be an applescript limitation. If it is, I realize
that qsort can be implemented with loops though IIRC it's a serious
brain-buster to follow. Maybe one of my old algorithms books has the
necessary code.

> One way to avoid using a top-level script object, and to get
> away from the calling handler having to know the name of the
> passed-handler, is to simply have the calling handler create
> it's own script object:

> on PassThisHandler()
> return "Successful !!!"
> end PassThisHandler

> on CallTheHandler( handlerParameter )

> script HoldAHandler
> property theHandler : handlerParameter
> end script

> return theHandler() of HoldAHandler

> end CallTheHandler

> CallTheHandler( PassThisHandler ) --> "Successful !!!"

> I think I like this method the best, as it allows the calling
> handler to define it's own names for things, ie: it doesn't
> have to know that the handler's defined-name is PassThisHandler.

I like this. I don't quite understand the design of *why* this works
but standard passing of a handler parameter doesn't, but this gives the
client interface I'm looking for. I also don't like the idea of having
the restrict the client name of the handler.


Michael

--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden


References: 
 >Please Pass the Handler (From: Arthur J Knapp <email@hidden>)

  • Prev by Date: Scripting Mail.app
  • Next by Date: coercing styled text to text
  • Previous by thread: Please Pass the Handler
  • Next by thread: Re: Please Pass the Handler
  • Index(es):
    • Date
    • Thread