Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Sorting multiple fields at one time......

 [1/3] from: jfdutcher1958::yahoo::com at: 21-Mar-2006 2:09


The script below works fine ..... and sorts the 'first' of the (4) fields which make up a 'logical' set into order, re-arranging the 'records' in the process. I have tried various options of the 'sort' syntax in trying to get the sort to sort either the first three fields (primary, 1st secondary, 2nd secondary) or, alternatively.....all (4) fields (if the last field is included.....not a problem)....but the Rebol syntax checker doesn't like any of them. Does anyone see the proper syntax to make the sort handle three of the four, or all four fields at once ??? Rebol[Title: "Test Case"] port: open/seek %/c/vetssrc/dietsys/dsysmst.txt read-record: func [port record-size record-number] [ copy/part at port record-number - 1 * record-size + 1 record-size ] substr: func [record offset len] [ copy/part at record offset len ] for i 1 299 1 [ rec1: read-record port 2690 i sortBlock: [] y: 1 regnbr: substr rec1 y + 3 4 lname: substr rec1 y + 7 15 fname: substr rec1 y + 22 15 minit: substr rec1 y + 37 1 if (regnbr <> "XXXX") [ append sortBlock lname append sortBlock fname append sortBlock mold minit append sortBlock regnbr ] ] print sort/skip sortBlock 4 halt

 [2/3] from: greggirwin::mindspring::com at: 21-Mar-2006 10:51


Hi John, If you add your records so each one is a sub-block, e.g.: if (regnbr <> "XXXX") [ repend/only sortBlock [lname fname mold minit regnbr] ] then you *should* just be able to use SORT without any refinements. I say should, because there may be cases where it doesn't work as you expect, but for consistently formatted blocks, it's pretty smart. Also, for loops that start at 1 and step by 1, REPEAT is *much* faster than FOR. FOR is a mezzanine while REPEAT is a native. -- Gregg

 [3/3] from: rebol:ccsducto:ar at: 3-Apr-2006 9:47


Hi John, to sort by more than one field you can do this: sort/skip/compare sortBlock 4 [1 4] This is SORT a serie 4 by 4 and compare the fields 1 and 4 4 is for /skip refinement [1 4] is for /compare refinement You can use any field in any order, for instance [4 3 2 1] or [3 1 2] or 4 For just one field you can use the integer (not block), the first field is the default Regards César ----- Original Message ----- From: "John Dutcher" <jfdutcher1958-yahoo.com> To: <rebolist-rebol.com> Sent: Tuesday, March 21, 2006 7:09 AM Subject: [REBOL] Sorting multiple fields at one time......
> The script below works fine ..... and sorts the 'first' of the (4) fields
which make up a 'logical' set into order, re-arranging the 'records' in the process.
> I have tried various options of the 'sort' syntax in trying to get the
sort to sort either the
> first three fields (primary, 1st secondary, 2nd secondary) or,
alternatively.....all (4) fields (if the last field is included.....not a problem)....but the Rebol syntax checker doesn't like any of them.