Sujet : Re: Self Study Question (mapcar) NOT HOMEWORK!
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 23. Jun 2025, 03:01:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103achf$vrgf$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
If you'll recall, in my answer to the initial post in this thread (where
the exercise was to implement this using MAPCAR), I said that in real life
this would probably be implemented using DO or LOOP. Then someone asked
for a recursive solution. Both the MAPCAR and recursive functions are
interesting academic problems, but they aren't necessarily the most natural
solution for this particular problem.
A simple, easy-to-understand solution, IMHO, is:
(defun pos+ (list)
(loop for pos upfrom 0
for element in list
collect (+ pos element)))
Crystal clear (even if you don't "like" LOOP, you should have little
trouble understanding it), and about as efficient as possible.
Gauche Scheme
(map + '(20 30 40 50 60 70) (liota))
===>
(20 31 42 53 64 75)
Is it true that users of CL inspired the making of
the movie "Idiocracy"?