From: bruno corcos

Subject: Re: Sorting

Date: 2003-2-24 18:17

(d1 m1 y1) < (d2 m2 y2)
= (lambda (d1 m1 y1 d2 m2 y2)
    (or (< y1 y2)
     (and (= y1 y2)
      (or (< m1 m2)
       (and (= m1 m2)
        (< d1 d2) ) ) ) ) )

not tested !!!


----- Message d'origine -----
De : "feilong" <coli.uni-sb.de at feilong>
¨¤ : <cs.berkeley.edu at allegro-cl>
Envoy¨¦ : lundi 24 f¨¦vrier 2003 23:51
Objet : Sorting


> Hallo friends, > We see again. I define a sort funktion "date-sort",which concerns sorting
of date. For example:
> (date-sort '((12 Jan 2002) (10 Jan 2002) (3 Nov 2000) (14 Apr 2003) (29
Sep 2003) (12 Aug 1999) (23 Nov 2001)))
> USER1>((12 Aug 1999) (3 Nov 2000) (23 Nov 2001) (10 Jan 2002) (12 Jan
2002) (14 Apr 2003) (29 Sep 2003))
> The result is very clear. That means that sorting is ascending. At first
we see the year of two dates, if they are not equal, then it whose number is large lies in front. Else if the year of two dates are equal, then we see month, if the month are not equal, then the date which is large lies in front. Else if the months are equal, we see the days. Regurd on month we treat them equal as year or month. I define a help funktion, in order to change month into number. Followings are my code:
> (defun month (month) > (cond ((equal month 'Feb) 2) > ((equal month 'Jan) 1) > ((equal month 'Nov) 11) > ((equal month 'Sep) 9)) > ) > > (defun date-sort (date-list) > (sort date-list #'(lambda (date1 date2) > (cond ((< (third date1) (third date2)) t) > ((< (month (second date1)) (month (second
date2))) t)
> ((< (first date1) (first date2)) t) > )))) > ;;Why is this application right, the order of date-list is right > CG-USER(9): (date-sort '((12 Jan 2002) (10 Jan 2002) (3 Nov 2000) (14 Apr
2003) (29 Sep 2003) (12 Aug 1999) (23 Nov 2001)))
> ((12 AUG 1999) (3 NOV 2000) (23 NOV 2001) (10 JAN 2002) (12 JAN 2002) (14
APR 2003) (29 SEP 2003))
> > ;;why is this application is not right, the order of date-list is not
right
> CG-USER(10): (date-sort '((12 Feb 2002) (10 Jan 2001) (3 Nov 2000) (29 Sep
2003)))
> ((29 SEP 2003) (3 NOV 2000) (10 JAN 2001) (12 FEB 2002)) > > Where is the problem in my code? Why does the second funktion application
not correct run?
> > Greetings > Xu > > > > >