Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #49546

Some sorting

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Some sorting
Date 2016-07-26 19:51 +0000
Organization A noiseless patient Spider
Message-ID <nn8evc$sb1$1@dont-email.me> (permalink)

Show all headers | View raw


Rainer Joswig wrote:

> > I have a list of lists. (("cal" "623") ("bill" "156") ("joe" "389"))
> > What is the most efficent way to sort a list like this in lisp, sorting
> > by either the numbers or the names?
> 
> How about:
> 
> ; By number
> 
> (let ((list '(("cal" "623") ("bill" "156") ("joe" "389"))))
>   (sort list #'< :key #'(lambda (item)
>                           (parse-integer (second item)))))

OCaml:

let compare' (a,b) (c,d) = compare (int_of_string b) (int_of_string d) ;;

List.sort compare' ["cal","623"; "bill","156"; "joe","89"];;

 ===>
[("joe", "89"); ("bill", "156"); ("cal", "623")]

In Forth?

-- 
Africans gang-rape and clitorectomize Finnish girl; government arrests Finn
whom they accuse of complaining:  http://www.wvwnews.net/story.php?id=6746

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

Some sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-26 19:51 +0000

csiph-web