Sort an array of composite structures: Difference between revisions

Content deleted Content added
Updated D code
m Superfluous parens
Line 1,177: Line 1,177:
[http://software-lab.de/doc/refB.html#by by] can be used. For example, to
[http://software-lab.de/doc/refB.html#by by] can be used. For example, to
sort by the first element
sort by the first element
<lang PicoLisp>: (by car sort '(("def" 456) ("abc" 789) ("ghi" 123))))
<lang PicoLisp>: (by car sort '(("def" 456) ("abc" 789) ("ghi" 123)))
-> (("abc" 789) ("def" 456) ("ghi" 123))</lang>
-> (("abc" 789) ("def" 456) ("ghi" 123))</lang>
or by the second element
or by the second element
<lang PicoLisp>: (by cadr sort '(("def" 456) ("abc" 789) ("ghi" 123))))
<lang PicoLisp>: (by cadr sort '(("def" 456) ("abc" 789) ("ghi" 123)))
-> (("ghi" 123) ("def" 456) ("abc" 789))</lang>
-> (("ghi" 123) ("def" 456) ("abc" 789))</lang>