[Openmcl-devel] Why not #"foo" for ns-strings?

Ron Garret ron at flownet.com
Wed Aug 26 06:24:12 UTC 2009


I started playing around with a package that co-opts the #@ reader  
macro, which in CCL is used to create constant ns-string objects.  It  
seems to me that this would be a natural candidate for the #" dispatch  
reader macro instead of #@, since the only character that can legally  
follow #@ is a double quote.

I also have this in my personal init.lisp file:

(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 #\« #\»)

This lets me use European-style «quotes» to create strings.  These  
have the advantage that they are self-balancing, so I can nest strings  
without having to use backslash escapes.  (There are also “smart  
quotes” characters which could be used to create self-balancing  
strings, but there's a bug in the readtable code at the moment that  
barfs on reader macros for characters whose code-char is >256.)

My question is: how would people feel about adopting one of these as a  
standard for ns-strings instead of #@?  Either #"foo" or #«foo» or  
#“foo”?  That would free up the #@ reader macro, and especially the  
last two would be at very low risk of collision with third-party code  
since no one is actually using unicode in their code despite the fact  
that all major implementations support it nowadays.  Existing code  
could be converted with a global search and replace of «#@"».

Thoughts?

rg




More information about the Openmcl-devel mailing list