• My First Lisp Program

    From Robert L.@21:1/5 to Ken Tilton on Sun Feb 13 03:32:44 2022
    Ken Tilton wrote:

    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)

    Gauche Scheme:

    (filter-map
    (^(n) (and (even? n) (* n n n)))
    (iota 22))

    ===>
    (0 8 64 216 512 1000 1728 2744 4096 5832 8000)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to All on Thu Jun 19 08:23:19 2025
    (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)

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