(define-thing <alpha>
(property-a 1)
(property-b 2))
a very raw version of the DEFINE-THING macro could be:
(library (things)
(export define-thing)
(import (rnrs))
(define-syntax define-thing
(lambda (stx)
(syntax-case stx (property-a property-b)
((_ ?name (property-a ?a) (property-b ?b))
#'(---))))))
which makes use of literals to match "keywords" in the
property list; but one can also do:
(library (things)
(export define-thing property-a property-b)
(import (rnrs))
(define-syntax property-a (identifier-syntax #f))
(define-syntax property-b (identifier-syntax #f))
(define-syntax define-thing
(lambda (stx)
(syntax-case stx (property-a property-b)
((_ ?name (?key-a ?a) (?key-b ?b))
(and (identifier? #'?key-a)
(free-identifier=? #'?key-a #'property-a)
(identifier? #'?key-b)
(free-identifier=? #'?key-b #'property-b))
#'(---))))))
which makes use of auxiliary syntaxes.
The second solution is the one adopted by some R6RS
implementations, for example Ikarus, implementing the
records' syntactic layer. Auxiliary syntaxes (when used
correctly) make it possible to rename the "keywords", for
example in Ikarus:
(import (rename (rnrs)
(mutable mu)
(immutable immu)))
(define-record-type thing
(fields (mu a)
(immu b)))
(define o (make-thing 1 2))
but aside of that, what other advantages do they have?
TIA
--
Marco Maggi
None, to my knowledge. I argued in the past against auxiliary sintax;
you may want to
read the last episode of my Adventures which is relevant to the
discussion here:
Ah, yes. I see this in R6RS[1]:
"A literal identifier matches an input subform if and only if the
input subform is an identifier and either both its occurrence in the
input expression and its occurrence in the list of literals have the
same lexical binding, or the two identifiers have the same name and
both have no lexical binding."
So, in truth, this:
(library (things)
(export define-thing property-a property-b)
(import (rnrs))
(define-syntax property-a (identifier-syntax #f))
(define-syntax property-b (identifier-syntax #f))
(define-syntax define-thing
(lambda (stx)
(syntax-case stx ()
((_ ?name (?key-a ?a) (?key-b ?b))
(and (identifier? #'?key-a)
(free-identifier=? #'?key-a #'property-a)
(identifier? #'?key-b)
(free-identifier=? #'?key-b #'property-b))
#'(---))))))
which is the same I posted before, but with an empty list of literals
(which should have been empty in my first post, too) is perfectly
equivalent to:
(library (things)
(export define-thing property-a property-b)
(import (rnrs))
(define-syntax property-a (identifier-syntax #f))
(define-syntax property-b (identifier-syntax #f))
(define-syntax define-thing
(lambda (stx)
(syntax-case stx (property-a property-b)
((_ ?name (property-a ?a) (property-b ?b))
#'(---))))))
Thanks.
[1] <http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-
H-13.html#node_sec_12.4>
--
Marco Maggi