• Re: Self Study Question (mapcar) NOT HOMEWORK!

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 23 02:01:20 2025
    From Newsgroup: comp.lang.lisp

    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"?
    --- Synchronet 3.21d-Linux NewsLink 1.2