Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"...a most excellent barbarian ... Genghis Kahn!" -- _Bill And Ted's Excellent Adventure_


devel / comp.lang.lisp / .Re: A simple lisp problem.

SubjectAuthor
o .Re: A simple lisp problem.Robert L.

1
.Re: A simple lisp problem.

<t15q8r$1lqi$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16986&group=comp.lang.lisp#16986

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!MOmOui1bQ+HBQTE09bwFKw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: A simple lisp problem.
Date: Sat, 19 Mar 2022 23:50:53 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t15q8r$1lqi$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="55122"; posting-host="MOmOui1bQ+HBQTE09bwFKw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sat, 19 Mar 2022 23:50 UTC

> >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

Using "every":

(define (diff1 xs)
(or (null? xs)
(every (compose ($ = 1 $) abs -) xs (cdr xs))))

Using recursion:

(define (diff1 xs)
(if (or (null? xs) (null? (cdr xs)))
#t
(if (= 1 (abs (- (car xs) (cadr xs))))
(diff1 (cdr xs))
#f)))

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor