Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You're ugly and your mother dresses you funny.


comp / comp.lang.lisp / .re: Another code review perhaps?

SubjectAuthor
o .re: Another code review perhaps?B. Pym

1
Subject: .re: Another code review perhaps?
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 6 Aug 2024 18:53 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: .re: Another code review perhaps?
Date: Tue, 6 Aug 2024 18:53:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <v8trg3$1pf9m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 06 Aug 2024 20:53:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="21065fed1fe3af72ee38292725a3b028";
logging-data="1883446"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7VlJm31HE47X/CCwWpkrg"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pLSy9o9SW6ri3Foss65vqOpH5VI=
View all headers

Martin Pomije wrote:

> This is my solution to Ex. 6 on p. 97 of Paul Graham's "ANSI Common
> Lisp"
>
> <QUOTE>
> Define iterative and recursive versions of a function that takes an
> object and a list, and returns a new list in which the object appears
> between each pair of elements in the original list:
>
> > (intersprerse '- '(a b c d))
>
> (A - B - C - C)
> <\QUOTE>
>
> (I'll just ask about the iterative solution I developed.)
>
> ;;;;Ex. 6
> (defun intersperse (element list)
> (let ((return-list (list (car list))))
> (do ((rest-input-list (cdr list) (cdr rest-input-list))
> (rest-return-list return-list (cddr rest-return-list)))
> ((not (consp rest-input-list)) return-list)
> (setf (cdr rest-return-list)
> (list element (car rest-input-list))))))

newLISP

(define (intersperse sep seq , A B)
(if (unify '(A B) (slice seq 0 2))
(begin (bind $it)
(append (list A sep) (intersperse sep (rest seq))))
seq))

(intersperse '- '(a b c d e f))

(a - b - c - d - e - f)

1

rocksolid light 0.9.8
clearnet tor