| Paste number 76415: | untitled |
| Pasted by: | trebor-dki |
| When: | 1 year, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1MYN |
| Channel: | #lisp |
| Paste contents: |
(defmacro rgl-print-symbols (&rest symbols)
"generate a (print (list 'symbol1 symbol1 .....) and print it
if last symbol is a stream -> (print (list ....) stream)"
(multiple-value-bind (printlist maybe-stream)
(loop
for symbol in symbols
collect (list `list `',symbol `,symbol) into print-symbol-list
finally (return (values print-symbol-list
(if (streamp `,symbol) `,symbol nil))))
(if maybe-stream
`(print (list ,@printlist) maybe-stream)
`(print (list ,@printlist)))))
(defun test---rgl-print-symbols ()
(let ((a "hallo"))
(with-open-file (rstream "test.txt"
:direction :output :if-exists :append
:if-does-not-exist :create)
(print (macroexpand-1 '(rgl::rgl-print-symbols a rstream)))
)))
Annotations for this paste:
| Annotation number 1: | untitled |
| Pasted by: | trebor-dki |
| When: | 1 year, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1MYN/1 |
| Paste contents: |
(let ((a "hallo"))
(with-open-file (rstream "test.txt" :direction :output :if-exists :append :if-does-not-exist :create)
(print (list 'a a 'rstream rstream))))
--->
(A "hallo" RSTREAM
#<SB-SYS:FD-STREAM for "file /home/DKI/gloecr/Sourcen/workdir/lisp/test.txt" {AD3DFA9}>)
| Annotation number 2: | Maybe this? |
| Pasted by: | nyef |
| When: | 1 year, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1MYN/2 |
| Paste contents: |
(defmacro rgl-print-symbols (first-arg &rest symbols)
(let ((list-args (loop for symbol in symbols
collect `(',symbol ,symbol))))
(if (listp first-arg)
`(print (list ,@list-args) ,(car first-arg))
`(print (list ',first-arg ,first-arg ,@list-args)))))
(rgl-print-symbols (some-stream) a b c d)
(rgl-print-symbols a b c d)
| Annotation number 3: | more clearly - maybe |
| Pasted by: | trebor-dki |
| When: | 1 year, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1MYN/3 |
| Paste contents: |
;; this is how it works till now
(let ((a "hello") (b "hello2"))
(rgl-print-symbols a b))
;;; ---->
(let ((a "hello") (b "hello2"))
(print (list 'a a 'b b)))
;;; this is what i would like to do it
(let ((a "hello") (b "hello2"))
(with-open-file (rstream "test.txt" :direction :output :if-exists :append :if-does-not-exist :create)
(rgl-print-symbols a b rstream)))
;;; --->
(let ((a "hello") (b "hello2"))
(with-open-file (rstream "test.txt" :direction :output :if-exists :append :if-does-not-exist :create)
(print (list 'a a 'b b 'rstream rstream) rstream)))
;;; or even perfect ---->
(let ((a "hello") (b "hello2"))
(with-open-file (rstream "test.txt" :direction :output :if-exists :append :if-does-not-exist :create)
(print (list 'a a 'b b) rstream)))