Paste number 10220: What is the problem with this code?

Index of paste annotations: 5 | 4 | 3 | 2 | 1

Paste number 10220: What is the problem with this code?
Pasted by: FZ
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
(defmacro dofile ((line filename) &body body)
  (with-gensyms (line)
    `(with-open-file (,stream ,filename)
      (loop for ,line = (read-line ,stream)
       while ,line do ,@body))))


;; my compiler says:
;; The value &BODY is not of type LIST.
;;   [Condition of type TYPE-ERROR]


;; however the code below compiles
;; aren't they very similar
;; what am I doing wrong?

(defmacro do-primes ((var start end) &body body)
  (with-gensyms (ending-value-name)
    `(do ((,var (next-prime ,start) (next-prime (1+ ,var)))
          (,ending-value-name ,end))
      ((> ,var ,ending-value-name))
      ,@body)))

Annotations for this paste:

Annotation number 5: similar problem with body
Pasted by: FZ
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW/5
Paste contents:
Raw Source | Display As
(defmacro dofile ((var filename) &body body)
  `(with-open-file (stream filename)
    (do ((,var (read-line stream nil nil) (read-line stream nil nil)))
        ((null ,var))
      ,@body)))

Annotation number 4: without passing the default value for the optional eof-value (which is NIL)
Pasted by: FZ
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW/4
Paste contents:
Raw Source | Display As
(defmacro dofile ((line filename) &body body)
  (with-gensyms (stream)
    `(with-open-file (,stream ,filename)
      (loop for ,line = (read-line ,stream nil)
       while ,line do ,@body))))

Annotation number 3: this looks better
Pasted by: FZ
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW/3
Paste contents:
Raw Source | Display As
(defmacro dofile ((line filename) &body body)
  (with-gensyms (stream)
    `(with-open-file (,stream ,filename)
      (loop for ,line = (read-line ,stream nil nil)
       while ,line do ,@body))))

Annotation number 2: probably what you wanted
Pasted by: salex
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW/2
Paste contents:
Raw Source | Display As
(defmacro dofile ((line filename) &body body)
  (with-gensyms (stream)
    `(with-open-file (,stream ,filename)
      (loop for ,line = (read-line ,stream)
       while ,line do ,@body))))

Annotation number 1: line shouldn't be in lambda list
Pasted by: salex
When:5 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7VW/1
Paste contents:
Raw Source | Display As
;;compare to this version
;;no comment on the wisdom of this macro :)

(defmacro dofile ((filename) &body body)
  (with-gensyms (line stream)
    `(with-open-file (,stream ,filename)
      (loop for ,line = (read-line ,stream)
       while ,line do ,@body))))

Colorize as:
Show Line Numbers
Index of paste annotations: 5 | 4 | 3 | 2 | 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.