Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[r6rs] auxiliary syntaxes vs literals

0 views
Skip to first unread message

marcomaggi

unread,
May 29, 2010, 1:49:50 AM5/29/10
to
When defining a new thing in Scheme style one can do:

(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

Michele Simionato

unread,
May 29, 2010, 10:20:40 AM5/29/10
to
On May 29, 7:49 am, marcomaggi <mrc....@gmail.com> wrote:
> Auxiliary  syntaxes (when  used
> correctly) make  it possible  to rename the  "keywords" <snip>

> but aside of that, what other advantages do they have?

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:

http://www.artima.com/weblogs/viewpost.jsp?thread=261364

marcomaggi

unread,
May 29, 2010, 2:53:15 PM5/29/10
to
On May 29, 4:20 pm, Michele Simionato <michele.simion...@gmail.com>
wrote:

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

0 new messages