• Re: CAR/CDR vs FIRST/REST

    From B. Pym@21:1/5 to Barry Margolin on Thu Sep 12 17:59:57 2024
    Barry Margolin wrote:

    (mapcan #'(lambda (x) (and (numberp x) (list x))) list)

    (loop for x in list
    when (numberp x) collect x)

    I agree with this example. Once I learned LOOP I never used the
    above idiom again.


    (filter number? '(a b c 1 2 3))

    (1 2 3)

    Does using "loop" cripple the brain, or do only those
    with crippled brains use "loop"?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Fri Sep 13 00:47:57 2024
    On 2024-09-12, B. Pym <Nobody447095@here-nor-there.org> wrote:
    Barry Margolin wrote:

    (mapcan #'(lambda (x) (and (numberp x) (list x))) list)

    (loop for x in list
    when (numberp x) collect x)

    I agree with this example. Once I learned LOOP I never used the
    above idiom again.


    (filter number? '(a b c 1 2 3))

    (1 2 3)

    Also, once you realize that "remove-if-not" is "keep-if":

    (remove-if-not #'numberp list)

    then you also will not use the poor "idiom":

    (mapcan #'(lambda (x) (and (numberp x) (list x))) list)

    Not to mention that once you learn that (lambda ...) is
    a macro which writes #'(lambda ...) for you, you will tend
    not to use the latter again.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

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