Marc Nieper-Wißkirchen
2016-07-20 14:10:02 UTC
Outside of library declarations and literals, identifiers in R7RS differ
from symbols in that they may be renamed due to hygienic macro expansion.
While this in general leads to the least surprises, it does not work well
with SRFI 99's record system, which needs symbols as field names and which
has already been debated here. While the power of the syntactic layer of
SRFI 99 (that is SRFI 131 plus minor additions) can be retained by using
position instead of name when subclassing (as in SRFI 136 and R6RS), even
when field names are identifiers, the procedural layer cannot distinguish
renamed symbols.
But...
Why has no one yet thought of using string literals instead of identifiers
when hygiene should not be applicable? String literals seem to possess all
the properties SRFI 99 needs for its field names and can readily be
interned via string->symbol when passing to the procedural layer so that no
performance loss occurs.
For example:
(define-record-type <parent>
(make-parent foo "bar")
parent?
(foo foo set-foo!)
("bar" bar set-bar!))
(define-record-type (<child> <parent>)
(make-child "bar" "baz")
child?
("baz" baz set-baz!))
In this example, foo can be a hygienically renamed field name (which makes
it possible that many fields of this name have been generated using
syntax-rules), while the field named "bar" can be referenced in
constructors of children.
Another advantage of this approach that it still works very well with
syntax-rules macros: These can check the equality of identifiers (in the
sense of bound-identifier=?) and also of string literals (they don't have
the power to check symbol equality, which is a disadvantage of a SRFI
99-approach without out string literals).
I think the idea above can be easily incorporated into SRFI 131 (and the
procedural layer of SRFI 99 when only string literals are used for field
names) making it compatible with R7RS again.
--
Marc
from symbols in that they may be renamed due to hygienic macro expansion.
While this in general leads to the least surprises, it does not work well
with SRFI 99's record system, which needs symbols as field names and which
has already been debated here. While the power of the syntactic layer of
SRFI 99 (that is SRFI 131 plus minor additions) can be retained by using
position instead of name when subclassing (as in SRFI 136 and R6RS), even
when field names are identifiers, the procedural layer cannot distinguish
renamed symbols.
But...
Why has no one yet thought of using string literals instead of identifiers
when hygiene should not be applicable? String literals seem to possess all
the properties SRFI 99 needs for its field names and can readily be
interned via string->symbol when passing to the procedural layer so that no
performance loss occurs.
For example:
(define-record-type <parent>
(make-parent foo "bar")
parent?
(foo foo set-foo!)
("bar" bar set-bar!))
(define-record-type (<child> <parent>)
(make-child "bar" "baz")
child?
("baz" baz set-baz!))
In this example, foo can be a hygienically renamed field name (which makes
it possible that many fields of this name have been generated using
syntax-rules), while the field named "bar" can be referenced in
constructors of children.
Another advantage of this approach that it still works very well with
syntax-rules macros: These can check the equality of identifiers (in the
sense of bound-identifier=?) and also of string literals (they don't have
the power to check symbol equality, which is a disadvantage of a SRFI
99-approach without out string literals).
I think the idea above can be easily incorporated into SRFI 131 (and the
procedural layer of SRFI 99 when only string literals are used for field
names) making it compatible with R7RS again.
--
Marc
--
You received this message because you are subscribed to the Google Groups "scheme-reports-wg2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheme-reports-wg2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "scheme-reports-wg2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheme-reports-wg2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.