I wrote the following code as part of a thin wrapper for LispWorks’ COM package, in order to make accessing properties in COM objects look more like s-expressions:
;;; Create dispatch function for '#<' and '#>'.
(eval-when (:load-toplevel :compile-toplevel :execute)
(defun com-dispatch-function (invoke-function)
(lambda (stream sub-char infix)
(declare (ignore sub-char infix))
(destructuring-bind (thing object &rest args)
(read stream)
`(,invoke-function ,object (symbol-name ',thing) ,@args)))))
;;; COM 'get property' read macro.
(set-dispatch-macro-character
## #<
(com-dispatch-function 'com::invoke-dispatch-get-property))
So now, instead of
(invoke-dispatch-get-property object "Property" argument)
I can write
#<(property object argument)
However when I try to use this syntax in a macro definition like so:
(defmacro something ((object) &body body)
(let ((excel (gensym)))
`(cclet* ((,excel #<(application ,object)))
,@)))
the compiler will complain for using a comma outside a backquote.
I guess the reason for the error is that the reader macro function should co-operate with the backquote syntax somehow, but I can not figure out a way to do that. Any suggestions?
Thanks!