Deutsch   English   Français   Italiano  
<v8trg3$1pf9m$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
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=
Bytes: 1928

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)