This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

problems with read macros

3 posts · 3322 views

i want a read-macro to do something with all symbols, with a comma before them, similar to quasiquote
it works, but if I use another read-macro inside my read-macro it can happen, that the other read-macro reads the commas first, and throws an error. how can I change this behavior

this is my macro definition:
(defun stream-replace (new &optional (stream *standard-input*))
  (case (peek-char t stream t)
    (#\,
      (read-char stream t)
      (let1 element (read stream t)
        (list element new)))
    (#\(
      (read-char stream t)
      (do ((list nil (cons (stream-replace new stream) list)))
        ((eq (peek-char t stream t) #\) ) (progn (read-char stream t) (reverse list)))))
    (otherwise
      (read stream t))))



(set-macro-character #\@ (lambda (stream char)
                           (declare (ignore char))
                           (let1 comma (get-macro-character #\,)
                             (set-syntax-from-char #\, #\x)
                             (stream-replace (read stream t) stream)
                             (set-macro-character #\, comma))))
I use @ as macro-character, i tried to disable read-macro for , but this is no good solution, I think

Re: problems with read macros

I can't see the exact problem here without seeing the other read-macro, but it might be clearer to set up a specific readtable for each use of the comma character that's different from the standard readtable.

Re: problems with read macros

yes, there is no problem in my read-macro,
also in quasiquote I cant use macros, if in them are comma operators.
I think, there is no proper solution.