>- Open Your Mind -<
Quoting from [EMAIL PROTECTED] (01-May-00 22:47:01).
f> I don't know if it is correct to use local variables in the sort function
f> (why not ?)
Why shouldn't it be indeed?
f> anyway they shouldn't be necessary
I just want to clear the table after the sort-method's dinner. I don't like leaving
the remains on the table.
f> ; if you have a simple record, that is data is visually separated, but
f> inside a single serie,
f> ; and you want to sort on a field different from the first, you can
f> ; first groups data in a serie of series, and then sort them.
f> ; This is precisely what the record-sort function does:
f> ; it creates a serie of series , sorts it, and then decompacts it
f> record-sort: func [record [block!] num [integer!]] [
f> tmp: copy []
f> new: copy []
f> foreach [a b ] record [append/only tmp reduce [a b]]
f> sort-method: func [a b] [ dump a b (at a num) < (at b num) ]
f> foreach rec sort/compare tmp :sort-method [append new rec]
f> return new
f> ]
... taken from the User's Guide, yes. It's inadequate for my case. Or maybe *I'm*
inadequate to the task. :-)
I don't have a simple record: it's several fields long, with some variable-type fields.
I tried writing my script using plain blocks (and a flat text file as storage), but I
kept getting lost in the several cases and subcases, losing track of which n-th field
was what and things like that. I'm not that good. (-:
So, I had to use a block of objects, with every object representing a record of my
database. This way, I can access every field by name, and every record by number (not
that I need to), and even combine the two things using the path notation (my
favourite): database/56/price .
May I now introduce my actual multiple-key sort-method?..
----------------------------------------------------------------------
sort-method: func [
a
b
] [
lesser: false
keys: head keys
until [
key: pick keys 1
either not none? key [
keys: next keys
if a/:key <> b/:key [
lesser: a/:key < b/:key
true
]
] [
true
]
]
lesser
]
----------------------------------------------------------------------
Oh, keys is a block dynamically built once per run and could evaluate to something
like [producer kind title] or [kind producer].
Now, if I add "/local lesser" to the spec block, the abort happens. I *hate* not
knowing why.
Alessandro Pini ([EMAIL PROTECTED])
"Goodnight, Dr. Frankenstein..." (Mulder)