[r6rs-discuss] Continuations and expansion

David Van Horn dvanhorn at cs.brandeis.edu
Tue Jul 24 19:00:16 EDT 2007


The following program captures and invokes continuations during
expansion.  I would expect the program to evaluate to #t, which is the
result according to Andre van Tonder's portable expander, but is this
behavior specified in the current draft?  My impression is yes,
although I'd like to make sure.

Thanks,
David

   (library (identifier-mapping)
     (export identifier-mapping-get identifier-mapping-put!)
     (import (rnrs)
             (rnrs mutable-pairs))

     (define m (list '()))

     (define (identifier-mapping-get id)
       (let loop ((map (car m)))
         (if (null? map)
             (error "no mapping.")
             (if (free-identifier=? id (caar map))
                 (cdar map)
                 (loop (cdr map))))))

     (define (identifier-mapping-put! id val)
       (set-car! m (cons (cons id val) (car m)))))


   (library (syntax-cc)
     (export syntax-let/cc syntax-invoke/c)
     (import (rnrs)
             (for (identifier-mapping) (meta 1)))

     (define-syntax syntax-let/cc
       (lambda (stx)
         (syntax-case stx ()
           ((_ x e)
            (call-with-current-continuation
             (lambda (k)
               (identifier-mapping-put! (syntax x) k)
               (syntax e)))))))

     (define-syntax syntax-invoke/c
       (lambda (stx)
         (syntax-case stx ()
           ((_ x e)
            ((identifier-mapping-get (syntax x))
             (syntax e)))))))

   (import (rnrs base)
           (syntax-cc))

   (syntax-let/cc k
                  (begin
                    (syntax-invoke/c k #t)
                    (let)))

   ;; ==> #t, not a syntax violation.



More information about the r6rs-discuss mailing list