[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] ANN: first draft of R7RS small language available



On Thu, 21 Apr 2011, Alex Shinn wrote:

> On Wed, Apr 20, 2011 at 12:45 AM, Andre van Tonder <andre@x> wrote:
>> On Tue, 19 Apr 2011, Alex Shinn wrote:
>>
>>> We're getting lost in the details on the individual points, and
>>> they pretty much all hinge on the one real question - are
>>> imported values required to be the "same" binding in terms of
>>> the syntax-rules pattern language?

Yes, it must be the same binding.  Otherwise nested QUASIQUOTE will break.

This is because QUASIQUOTE is both a binding AND A KEYWORD.

Here is a naive def of quasiquote

(module (base)
   (export quasiquote)   ;; at least QUASIQUOTE has to be bound and exported
                         ;; independent of what you do with UNQUOTE/SPLICING
   (define-syntax quasiquote
      (syntax-rules (unquote unquote-splicing quasiquote)

                   ;; NOTE HERE QUASIQUOTE IS A KEYWORD
                   ;; THAT MATCHES THE BINDING OF QUASIQUOTE IN (BASE)

        ((_ (unquote form))
         form)
        ((_ ((unquote-splicing form) . rest))
         (append form (quasiquote rest)))
        ((_ (quasiquote form) . depth)
         (list 'quasiquote (quasiquote form #f . depth)))
        ((_ (unquote form)  x . depth)
         (list 'unquote (quasiquote form . depth)))
        ((_ (unquote-splicing form) x . depth)
         (list 'unquote-splicing (quasiquote form . depth)))
        ((_ (car . cdr) . depth)
         (cons (quasiquote car . depth) (quasiquote cdr . depth)))
        ((_ #(elt ...) . depth)
       (list->vector (quasiquote (elt ...) . depth)))
      ((_ atom . depth)
       'atom)))
   ) ; end module

   (module (mine)
     (import (only (base) QUASIQUOTE))
     (define x 1)
     (quasiquote (quasiquote (unquote (unquote x)))))

If the imported QUASIQUOTE in (MINE) does not refer to the same binding as the 
QUASIQUOTE above in (BASE), then the code walker in the SYNTAX-RULES definition 
above won't interpret the nested QUASIQUOTE in the last line correctly.

Andre

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports