Discussion:
CAR/CDR vs FIRST/REST
(too old to reply)
B. Pym
2024-09-12 17:59:57 UTC
Permalink
(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"?
Kaz Kylheku
2024-09-13 00:47:57 UTC
Permalink
Post by B. Pym
(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: @***@mstdn.ca
Loading...