Malice
4/10/2016 12:05:00 AM
So I was reading throught PG's On Lisp, and when dealing with do-tuples/o, I wrote it down and tested it:
(defmacro do-tuples/o (params source &body body)
(when params
(with-gensyms (src)
`(prog ((,src ,source))
(mapc (lambda ,params ,@body)
,@(map0-n (lambda (n) `(nthcdr ,n ,src))
(1- (length params))))))))
The version is slightly changed, but no change in logic was made.
Now the other time I was reading errata to On Lisp, and I found this:
p. 156. In do-tuples/o the expression (1- (length parms)) should be (- (length source) (length parms)). Reported by Roland. (at netquant.com.br)
So I changed the code:
(defmacro do-tuples/o (params source &body body)
(when params
(with-gensyms (src)
`(prog ((,src ,source))
(mapc (lambda ,params ,@body)
,@(map0-n (lambda (n) `(nthcdr ,n ,src))
(- (length source) (length params))))))))
Now let's run both macros in the following example:
(do-tuples/o (a b) '(a b c d)
(princ (list a b)))
To my surprise, the first example works as intended, while the second one results in an error. Is the errata wrong, and the original correct?