[r6rs-discuss] Continuations and expansion
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.
Received on Tue Jul 24 2007 - 19:00:16 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC