[Openmcl-devel] Using readtables for only one library

Ron Garret ron at flownet.com
Mon May 10 17:48:30 UTC 2010


On May 10, 2010, at 10:44 AM, Dan Weinreb wrote:

> James Anderson kindly pointed me to Edi Weitz's cl-interpol, which
> does this.  http://www.weitz.de/cl-interpol/
> 
> It's not the only thing I was thinking of doing with
> the readtable.  Ruby also lets you type in strings
> with single-quotes (which does not do interpolation).
> I was thinking of allowing that. 
> (If you want to quote something, just use backquote.)

This is one of my pet reader macros:

(defun make-string-reader (c1 c2)
  (set-macro-character
   c1
   (lambda (stream c)
     (declare (ignore c))
     (with-output-to-string (s)
       (loop for c = (read-char stream)
         with cnt = 1
         if (eql c c1) do (incf cnt)
         else if (eql c c2) do (decf cnt)
         until (and (eql c c2) (eql cnt 0))
         do (princ c s))
      s))
   t))

(make-string-reader #\« #\»)
(make-string-reader #\“ #\”)

This lets you use balanced quotes for strings, which lets you write nested strings without having to use backslash escapes.  We have unicode.  We might as well use it.

rg




More information about the Openmcl-devel mailing list