| Deutsch English Français Italiano |
|
<v4j2p1$3a0lu$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <No_spamming@noWhere_7073.org>
Newsgroups: comp.lang.lisp
Subject: .Re: A simple lisp problem.
Date: Sat, 15 Jun 2024 03:45:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <v4j2p1$3a0lu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 15 Jun 2024 05:45:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="14b864f2885e341cc55dd1b97ca84b7c";
logging-data="3474110"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+3L1YqXC7m8OXi/827dAw"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:9duSjKewJxXHEMr78GMzma4MR6w=
Bytes: 1672
Frank Schwieterman 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 (diff1? xs)
(every
(lambda (a b) (= 1 (abs (- a b))))
xs
(cdr xs)))
(diff1? '(2 3 4 3 4 5 6 7 8 9 8))
===>
#t
(diff1? '(2 3 4 3 4 5 6 7 8 9 8 0))
===>
#f