Looking for alternative read-time constructor syntax
I rely on srfi:10 read-time constructor
#,(tag datum ...) a lot.
It does have a dark corner (there's no clear semantics to
make sure a particular tag be available at the time
it is read), but having a uniform syntax and a standard way
to extend it is indispensable for practical applications.
So, it is very unfortunate that R6RS made an incompatible choice.
#,X is taken for
Although I don't plan to make Gauche fully comform R6RS,
I'd like to make it compatible to R6RS as much as possible,
and it is desirable to be able to read R6RS code.
The plan is to switch the reader: In R6RS mode,
#, is for
for srfi-10. After all, you can write unsyntax without using
abbreviation, but you cannot write read-time constructor
in other ways.
However, there will be a time that someone wants to write abbreviated unsyntax and read-time constructor in one file. It won't harm to have alternative read-time constructor syntax for more flexibility.
Specifically, I'm thinking to make records (ref:gauche.record)
printable by default. Just like Common Lisp's struct,
but it would be better to use existing srfi-10 syntax
instead of inventing a new syntax. If records have
standard external representation,
I expect the srfi-10 syntax appear in the data and code a lot more
frequently. If Gauche adopts
syntax-case, the demand
of using abbreviated unsyntax will also grow. I see
potential of conflict here.
★ ★ ★
What would be a good choice for alternative syntax of read-time constructor? I don't have a concrete idea yet. I just record some ideas here for future reference and discussion.
#.(tag datum ...): Borrows from read-time eval syntax of Common Lisp. I bet the chance that Scheme standard adopts read-time evaluation is a lot smaller than it adopts read-time constructor: The former opens a big can of worms on what environment the expression should be evaluated. The similarity of read-time evaluation and read-time construction, however, could lead more confusion than other choices.
#!ctor(tag datum ...): The ctor word can be different. This is a valid syntax in R6RS, in which
#!ctorpart is just treated as a comment and the whole expression is read as a list. I'm not sure whether it is a good thing or not, though. It is also more verbose than other choices.
#!(tag datum ...): Some implementations (and past RnRS's) uses
#!as a prefix for special data, e.g.
#!null. This choice can be seen as an extention to it. A disadvantage: If this appears at the top of the file, it can be mistaken to be an interpreter line.
#@(tag datum ...): The character
@is kind of arbitrary. ChezScheme uses this prefix for fasl objects. It gives me a sort of "internal representation" feeling. Maybe too arbitrary.
#$(name datum ...): I think this more as a dedicated syntax for records. Well, it looks like Common Lisp's
#S(...), and it would be more compact than
#,(record name datum ...). Chicken uses
#$for a special purpose so we conflict with it.
Tags: R6RS, srfi-10, syntax, gauche.record
Post a comment