From: Hank Heijink
Subject: Re: A simple lisp problem.
Date: 
Message-ID: <heijink-0212971658570001@socsci140.socsci.kun.nl>
In article <···············@jagor.srce.hr>, Hrvoje Niksic
<·······@srce.hr> wrote:

> Joe Ng <·····@isu.edu> writes:
> 
> > Hi,
> > 
> > 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
> > 
> > If anyone can let me see the code, it will help me catch up this
> > language. Thanks,
> 
> Oh, it's that time of the year.  Try this:
> 
> (defun difference (foo)
>   (or (null foo)
>       (and (= 1 (abs (- (car foo) (cadr foo))))
>            (difference (cddr foo)))))
> 
> As a reward, followup to this with an explanation of how it works. :-)

Of course, this will produce an error if foo has an uneven number of
elements. Add a separate case for a list containing one element and you're
done.

Hank