problems with read macros

Discussion of Common Lisp
Post Reply
porky11
Posts: 25
Joined: Fri May 02, 2014 6:46 am

problems with read macros

Post by porky11 » Wed Dec 10, 2014 11:40 am

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:

Code: Select all

(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

David Mullen
Posts: 78
Joined: Mon Dec 01, 2014 12:29 pm
Contact:

Re: problems with read macros

Post by David Mullen » Wed Dec 10, 2014 2:10 pm

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.

porky11
Posts: 25
Joined: Fri May 02, 2014 6:46 am

Re: problems with read macros

Post by porky11 » Thu Dec 11, 2014 8:38 am

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.

Post Reply