• .re: Another code review perhaps?

    From B. Pym@21:1/5 to Martin Pomije on Tue Aug 6 18:53:59 2024
    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)