home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!rphroy!cmsa.gmr.com!KGODDEN
- From: KGODDEN@cmsa.gmr.com
- Newsgroups: comp.sys.mac.hypercard
- Subject: Re: HC 2.1 "sort" command
- Message-ID: <168587D0B.KGODDEN@cmsa.gmr.com>
- Date: 4 Sep 92 13:53:28 GMT
- References: <1992Sep3.224521.5605@kronos.arc.nasa.gov>
- Sender: news@rphroy.ph.gmr.com
- Organization: GM Research Labs
- Lines: 42
- Nntp-Posting-Host: cmsa.gmr.com
-
- In article <1992Sep3.224521.5605@kronos.arc.nasa.gov>
- joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91) writes:
-
- >
- >Hey, macnetters:
- >
- >I have a simple question I hope you can help me to answer.
- >
- >Suppose I have a script with the following line:
- >
- >put "name 2" & return & "name 5" & return & "name 21" & return &
- > "name 1" & return into abc
- >
- >and I want to sort the lines in that var by the number which is the last word
- >of each line.
- >
- <stuff deleted>
-
- You're right. You can't sort this as is. You COULD do it if you were sorting
- CARDS (as opposed to the contents of a variable) where that info appeared in
- some field. This is a bewildering incompatibility between the card sort
- and the variable sort, and CERTAINLY ought to be fixed in the next update
- of HC (are you listening Claris?--check out the &key parameter in the
- Common Lisp sort, that's what you need in HC).
-
- So what to do?....The solution I used (with help from others on the net)
- in a similar situation was to transform each line of the variable such that
- sort would give the correct order I wanted, and then transform each line of
- the result back again. For you, (IF your example is literally representative)
- this could be done by reversing the words of each line, sorting, and then
- reversing each line back again. I.e. instead of sorting
- name 2
- name 5
- name 21
- name 1
- you would transform each into e.g. 2 name, 5 name, etc. Then do your sort
- and then put the nums back to the end of each line.
- It's an ugly hack, but it'll stem the dike until Claris does it the Right Way.
- -Kurt
- --------------------
- "I distrust a research person who is always obviously busy on a task."
- -Robert A. Frosch, VP, GM Research
-