|
(defmacro do-tuples/o (parms source &body body) |
As macro do-tuples/o describe in chapter 11, define like bellow:
;; problem reported to pg but not checked -- test this!!!!!!!!!!
;; http://www.paulgraham.com/onlisperrata.html:
;; p. 156. In do-tuples/o the expression (1- (length parms)) should be
;; (- (length source) (length parms)).
;; Reported by Roland. (at netquant.com.br)
(defmacro do-tuples/o (parms source &body body)
(if parms
(let ((src (gensym)))
`(prog ((,src ,source))
(mapc (lambda ,parms ,@body)
,@(map0-n (lambda (n)
`(nthcdr ,n ,src))
;;(1- (length parms)) ;; error in text
(- (length source) (length parms)) ;; corrected
))))))
should works like following:
CL-USER> (do-tuples/o (x y) '(a b c)
(princ (list x y)))
(A B)(B C)
NIL
However, in expression (- (length source) (length parms)) ,
(length source) will always eval to 2 (because of quote expression ),
What's worse, the number of list value return by
,@(map0-n (lambda (n)
`(nthcdr ,n ,src))
(- (length source) (length parms))
is not equal to number of parms(which is required by operator mapc)
I foud the origin (1- (length parms)) is right. May I miss somthing?
on-lisp/src/chapter-11.lisp
Line 159 in b13e8b6
As macro
do-tuples/odescribe in chapter 11, define like bellow:should works like following:
However, in expression
(- (length source) (length parms)),(length source)will always eval to 2 (because of quote expression ),What's worse, the number of list value return by
is not equal to number of parms(which is required by operator
mapc)I foud the origin
(1- (length parms))is right. May I miss somthing?