William James
1/20/2016 11:07:00 AM
WJ wrote:
> Barry Margolin wrote:
>
> > 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.
I see two FORs. Does that mean that there are two nested loops?
MatzLisp (Ruby):
[300,400,500,600].map.with_index &:+
==>[300, 401, 502, 603]
Therefore, map is the most natural solution in a Lispy language.
--
Elie [Wiesel] thus could have remained at Birkenau to await the Russians.
Although his father had permission to stay with him as a hospital patient or
orderly, father and son talked it over and decided to move out with the
Germans. --- Robert Faurisson