From Newsgroup: comp.lang.lisp
B. Pym wrote:
I am Lisp beginner and I am doing a simple execise on lisp. I was asked to write a lisp program , by using either recursion or do, to return
true if the difference between each successive pair of the them is 1.
ie:
(difference '(2 1))
T
(difference'(3 4 5 6 5 4))
T
(differnce '(3 4 5 3))
NIL
....
(defun difference (param)
(if (> (length param) 1)
(if (<= (abs (- (first param) (first (rest param)))) 1 )
(difference (rest param))
nil
)
T
)
)
Gauche Scheme
(define (difference xs)
(do ((ok #t))
((or (null? xs) (not ok)) ok)
(let1 x (pop! xs)
(if (pair? xs)
(set! ok (= 1 (abs (- x (car xs)))))))))
Shorter.
(define (difference xs)
(do ((ok #t
(let1 x (pop! xs)
(if (null? xs) #t (= 1 (abs (- x (car xs))))))))
((or (null? xs) (not ok)) ok)))
--
[T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
--- Kenny Tilton
The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2