SLOOP -> ANSI LOOP translation



   From: ole.rohne at cern
   
   It would be interesting to know what implementations return for the
   following:
   
   (defun nleft (n x &optional tail)
     (loop for v on (nthcdr n x)
           for w on x
           when (eq v tail) do (return w)
           finally (return w)))
   
   (nleft 1 '(0 1))
   
   SLOOP says '(1), while MIT LOOP says '(0 1). I had assumed MIT LOOP is
   correct but I haven't checked.

I think the MIT result conforms to ANSI.  The loop terminates as soon
as the v `for' iterator terminates, transfering to the finally clause
and preventing the w iterator from stepping.  I expect you really want
to express it this way which will probably work with either variant:

   (defun nleft (n x &optional tail)
     (loop for w on x
           for v on (nthcdr n x)
           when (eq v tail) do (return w)
           finally (return w)))

It could probably also be expressed more efficiently without the
automatic termination tests something like this (untested):

   (defun nleft (n x &optional tail)
     (loop as v = (nthcdr n x) then (cdr v)
           as w = x then (cdr w)
           when (eq v tail) do (return w)
           finally (return w)))