[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: Style questions

William James

9/5/2015 4:13:00 PM

Alan Crowe wrote:

> Consider trying to lift the concept of inequality from
> operating on a pair of numbers to operating on two lists of
> numbers with the left most number being decisive.
>
> (defun compare (x y)
> (cond ((and (endp x)
> (endp y)) 'equal)
> ((endp x) 'less)
> ((endp y) 'more)
> ((< (car x)
> (car y)) 'less)
> ((> (car x)
> (car y)) 'more)
> ('equal-heads (compare (cdr x)
> (cdr y)))))

Gauche Scheme:

(use gauche.lazy :only (lmap))

If the lists are equal up to the last item of the shorter list,
the longer list is considerer greater.

(define (compare-lists lst1 lst2)
(or
(find ($ not $ zero? $) (lmap compare lst1 lst2))
(compare (length lst1) (length lst2))))

gosh> (compare-lists '(2 "foo") '(2 "foo"))
0
gosh> (compare-lists '(2 "foo" 0) '(2 "foo"))
1
gosh> (compare-lists '(2 "foo" 0) '(2 "foo" 9))
-1

--
Swedes are now in many ways treated as second-class citizens in their own
country. The very word "Swede" has been given a negative connotation. This kind
of project has now been introduced all over Western Europe.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html