Sujet : Re: My First Lisp Program
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 19. Jun 2025, 09:23:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1030hdl$3p7ai$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
(defun filter (fn list) ; CL has a separate namespace for variables,
; so LIST is a perfectly good variable name.
(loop
:for elt :in list
:when (funcall fn elt)
:collect elt))
Great, Pillsy, you just broke the OP's function. Let us hope it is
indeed "not used?". The Op was accumulating the fn return value, not the
original list element. Ergo:
(loop for e in list when (funcall fn e) collect it)
Let's see if we can make it shorter by using a Lispy language
instead of CL.
Gauche Scheme:
(define (fn x) (and (zero? (mod x 3)) (* 10 x)))
(filter-map fn (iota 22 1))
===>
(30 60 90 120 150 180 210)