[Openmcl-devel] ccl manual (was Re: trace on recursive functions)

Ron Garret ron at flownet.com
Mon Dec 14 10:06:37 PST 2009


On Dec 14, 2009, at 9:13 AM, Brian Mastenbrook wrote:

> On 12/13/2009 7:33 PM, Ron Garret wrote:
>> 
>> On Dec 13, 2009, at 12:30 PM, Brian Mastenbrook wrote:
>> 
>>> I personally find editing text in S-Expressions to be incredibly
>>> cumbersome. Quite a lot of my code is mixed XML/S-Expressions done with
>>> a reader macro that allows me to write things like (<a href="test">
>>> "Text!"), and while this works for layout in web applications I'd go mad
>>> trying to read things like "This is a bit of text that has \"quotes\"
>>> and \"\\"\" (backslashes) in it".
>> 
>> Then I have good news for you too.  There is another cool new technology called Unicode, which gives you access to additional characters beyond those in the traditional ASCII repertoire.  In particular, Unicode gives you access to a number of different styles of balanced quotation marks.  Balanced quotation marks can be nested, and also allow one level of traditional unbalanced quotes to be contained, all without any escape characters.  e.g.
>> 
>> «Balanced quotes can be «nested» and can contain "unbalanced quotation marks" without any escape characters.»
> 
> Clearly for a documentation-oriented wiki, there will be a need to use the standard quotation marks that Common Lisp uses. Your funny Unicode quotations are just constituent characters to the default reader.

Guess what!  More good news!  (One of these days you are going to notice a pattern developing here.)  You can actually *change* the Lisp reader!  Yourself! Easily!  Here's the code:

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

Or, if you prefer:

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

>  Furthermore, it's not easy to input these characters for most users.

It's easy if you're on a Mac.  Just edit ~/Library/KeyBindings/DefaultKeyBinding.dict thusly:

{
  "~[" = ("insertText:", "\U00AB");
  "~]" = ("insertText:", "\U00BB");

  "~{" = ("insertText:", "\U201C");
  "~}" = ("insertText:", "\U201D");
}

Then you can type «» using option-[ and option-], and “” using option-shift-[ and option-shift-].  Adjust to suit your own taste.

I'm sure there's a similar recipe for Windows and Linux.

rg




More information about the Openmcl-devel mailing list