• 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: Sorting? [sorted]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting? [sorted]


  • Subject: Re: Sorting? [sorted]
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Fri, 13 Sep 2002 10:56:01 -0400

> Date: Thu, 12 Sep 2002 19:44:09 +0100
> From: has <email@hidden>
> Subject: Re: Sorting? [sorted]

> Goran Ehn wrote:
>> Does anyone have a sorting routine that sorts name/numbers correctly?

> 1. you take your existing sort routine and mangle it to make it to do this
> special-case sort of yours

> 2. you take your existing sort routine and move the comparison part out of
> the sort handler and into its own handler. You then modify the comparison
> handler alone.

I also used option 2, but with a twist:

The problem with the comparison handler is that it has to munge/mangle
a single item of the list each time it encounters it, which could be many
times throughout the sort. I perform a modification to every item of the
list before calling the sort, ensuring that the items were in a sort-
ready state. The text item delimiters make this "pre-digestion" very
speedy, despite the length of the code.


> So, here's the Guidebook sort routine [2]

> --generalised sort code
>
> on ASCIISort(myList)

What a strange contradition. Our comment tells us that this is a
"generalised" sort, and then it calls the sort, "ASCII..." something.
Look, I'm not one of those people who gets upset about a phrase like,
"high-bit ascii", because everyone knows what is meant. But to call
a sort routine "ascii", when the relative ordering of the character
codes plays very little part in the sort, is just silly. An "ascii"
sort should place "A" before "a", etc.

> Because of some implementation crappiness in AS, you have to wrap your
> comparison routine inside a script object: you can't just feed the handler
> direct to the sort routine [3].

Not entirely true, but I suppose you know that, based on your footnote,
(which you misnumbered):

> [2] Yes, small white lie. Yes, for your own good. No, I don't want to argue
> it.:p

A handler can be passed directly to another handler, via one of two
methods:

(* Via Property
*)
property handler_hold

on MainHandler( handler_parameter )

set handler_hold to handler_parameter
handler_hold() --> call the handler


(* Via Script Object
*)
on MainHandler( handler_parameter )

script internal_script
property internal_handler : handler_parameter
end

internal_handler() of internal_script


> [1] Okay, three options if you count rolling a completely non-standard,
> highly specialised piece of code from scratch [JD's?], but I really can't
> recommend that approach: you want to make your life _easier_, not harder.

But JD's solution was quite elegant, and given the need in AppleScript
for speedy solutions, I really liked it. :)


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: List Mail's mailbox hierarchy w AppleScript?
  • Next by Date: Re: Error resolving references
  • Previous by thread: Re: Sorting? [sorted]
  • Next by thread: Re: Sorting? [sorted]
  • Index(es):
    • Date
    • Thread