[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Sorting by enumeration

William James

12/27/2015 11:19:00 PM

Slobodan Blazeski wrote:

> See below to get some idea , it's very ugly and quick-n-dirty but it
> looks like that it works, sorry no time to clear it & test it more
> thoroughly.
>
> (defun be4 (a b)
> (cond ((< (position (car a) *numbers*)
> (position (car b) *numbers*))
> t)
> ((> (position (car a) *numbers*)
> (position (car b) *numbers*))
> nil)
> (t
> (if (< (position (cdr a) *letters*)
> (position (cdr b) *letters*))
> t))))
>
> (defun number-and-letter (values)
> (sort values #'be4))
>
> (number-and-letter '((3 . F) (3 . A) (4 . C) (4 . B) (2 . A) (6 . C)
> (7 . E)))
> =>((2 . A) (3 . A) (3 . F) (4 . B) (4 . C) (6 . C) (7 . E))

MatzLisp (Ruby):

[[3,"F"],[3,"A"],[4,"C"],[4,"B"],[2,"A"],[6,"C"],[7,"E"]].sort
===>
[[2, "A"], [3, "A"], [3, "F"], [4, "B"], [4, "C"], [6, "C"], [7, "E"]]

--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K...)
1 Answer

William James

4/9/2016 12:40:00 PM

0

WJ wrote:

> Slobodan Blazeski wrote:
>
> > See below to get some idea , it's very ugly and quick-n-dirty but it
> > looks like that it works, sorry no time to clear it & test it more
> > thoroughly.
> >
> > (defun be4 (a b)
> > (cond ((< (position (car a) numbers)
> > (position (car b) numbers))
> > t)
> > ((> (position (car a) numbers)
> > (position (car b) numbers))
> > nil)
> > (t
> > (if (< (position (cdr a) letters)
> > (position (cdr b) letters))
> > t))))
> >
> > (defun number-and-letter (values)
> > (sort values #'be4))
> >
> > (number-and-letter '((3 . F) (3 . A) (4 . C) (4 . B) (2 . A) (6 . C)
> > (7 . E)))
> > =>((2 . A) (3 . A) (3 . F) (4 . B) (4 . C) (6 . C) (7 . E))
>
> MatzLisp (Ruby):
>
> [[3,"F"],[3,"A"],[4,"C"],[4,"B"],[2,"A"],[6,"C"],[7,"E"]].sort
> ===>
> [[2, "A"], [3, "A"], [3, "F"], [4, "B"], [4, "C"], [6, "C"], [7, "E"]]

OCaml:

List.sort compare [3,"F";3,"A";4,"C";4,"B";2,"A";6,"C";7,"E"];;

===>
[(2, "A"); (3, "A"); (3, "F"); (4, "B"); (4, "C"); (6, "C"); (7, "E")]

--
The former leader of the National Front Jean-Marie Le Pen was fined 30,000
euros for exposing the Jews Holocaust gas chamber hoax.
infostormer.com/jean-marie-le-pen-fined-30000-euros-for-exposing-jewish-holocaust-gas-chamber-hoax