Anton van Straaten <anton@appsolutions.com> wrote:
+---------------
| Out of interest, though, how does read-square-bracket-as-paren deal with
| files using different conventions? Presumably if you're compiling
| explicitly, you can compile different files with different settings, but
| what if you have a non-bracketed program that wants to load bracketed PLT
| code taken from somewhere else, using "load"? I guess that simply has
| to be avoided?
+---------------
Yup:
% echo '(+ 3 [* 4 5])' >foo
% mzscheme
[...banner chatter...]
> (load "foo")
23
> (read-square-bracket-as-paren #f)
> (load "foo")
reference to undefined identifier: |[*|
>
But of course, you could always do this, I suppose, when you
wanted to load some code in the other style:
> (define (my-load file)
(parameterize ((read-square-bracket-as-paren #t)
(read-curly-brace-as-paren #t))
(load file)))
> (my-load "foo") ; the parameters are dynamically bound
23
> (load "foo") ; and restored after "parameterize" returns
reference to undefined identifier: |[*|
>
+---------------
| >And by providing a customized reader:
| > <URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node125.htm>
| >that peeks one character ahead of the standard reader (and calls it
| >if the character isn't one you want to handle), I see no reason you
| >couldn't direct implement (say) BRL syntax in PLT Scheme.
|
| Thanks. I have been assuming that such a routine would need to be somewhat
| context-sensitive, e.g. to avoid fiddling with characters in comments or
| quoted strings...
+---------------
That's why I specifically said "*peek* one character ahead"
instead of "read". When called, you handle the special characters
you want to, and also must eat whitespace and, unfortunately,
comments (can you see why?), but for everything else you just
call the standard "read" handler (which you saved away before
installing your own).
+---------------
| so being lazy, I thought that if I really wanted to, perhaps
| I could find the place where double-quotes are handled within
| the MzScheme reader, and sneak an alternative character in there.
+---------------
Hmmm... That would be a *lot* harder, I suspect. There's no direct
equivalent in PLT Scheme of Common Lisp's "readtable" notion that
allows dispatching to user-defined read handlers optionally on a
per-character basis. In PLT Scheme, you either handler all of it
(possibly calling the saved reader for some constructs), or none of it.
-Rob
-----
Rob Warnock, 30-3-510 <rpw3@sgi.com>
SGI Network Engineering <http://www.meer.net/~rpw3/>
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA
[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]