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

[REBOL] Re: sort/compare

From: carl:cybercraft at: 8-Nov-2002 10:10

On 07-Nov-02, guimond wrote:
> Hi > I try to sort a series of blocks on the second element of the block > which represents the age of individuals. > rebol [] > person: make block! [ name age ] > damien: make person [ "Damien" 20 ] > fabien: make person [ "Fabien" 1 ] > list-of-person: [ Damien Fabien ] > age-comp: func [ a b ] [ (second a) < (second b) ] > sort/compare list-of-person :age-comp > Script Error: second expected series argument of type: series pair > event money date object port time tuple any-function struct event > ** Where: halt-view > ** Near: probe second a > The comparator function works though! >>> age-comp Damien Fabien > == false > How can I sort my series on the age ? > thanks for help!
Hi Philippe, You were almost there. The... list-of-person: [ Damien Fabien ] will just be a block containing the words Damien & Fabien, not the contents of the Damien and Fabien blocks, as can be seen at the REBOL console...
>> list-of-person: [ Damien Fabien ]
== [Damien Fabien]
>> probe list-of-person
[Damien Fabien] == [Damien Fabien] Reducing the block will give you what (I assume) you want though...
>> person: make block! [ name age ]
== [name age]
>> damien: make person [ "Damien" 20 ]
== ["Damien" 20]
>> fabien: make person [ "Fabien" 1 ]
== ["Fabien" 1]
>> list-of-person: reduce [ Damien Fabien ]
== [["Damien" 20] ["Fabien" 1]] Your sort function will then work...
>> age-comp: func [ a b ] [ (second a) < (second b) ] >> sort/compare list-of-person :age-comp
== [["Fabien" 1] ["Damien" 20]] Hope that helps. -- Carl Read