| 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: |
(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: |
(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: |
(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: |
(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: |
(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: |
;;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))))