www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

assumption-local-expand-reuse-let-bound-id.rkt (1078B)


      1 #lang racket
      2 (require (for-syntax racket/syntax))
      3 ;; x is first bound with a let inside the local-expanded code.
      4 ;; The identifier is extracted (presumably with that let's scope,
      5 ;; and re-uesd as a definition outside of the let.
      6 ;; Check that this is okay (no "ambiguous identifier" or "identifier
      7 ;; used out of context" error.
      8 (define-syntax (test stx)
      9   (syntax-case stx ()
     10     [(_ e)
     11      (let ()
     12        (define/with-syntax whole
     13          (local-expand #'(let-values ([(e) 2]) e) 'expression '()))
     14        (define/with-syntax (_ _ xx) #'whole)
     15        #'(let-values ()
     16            (define xx 3)
     17            (list xx
     18                  whole)))]))
     19 
     20 (let ([x 1])
     21   (test x))
     22 
     23 (define-syntax (test2 stx)
     24   (syntax-case stx ()
     25     [(_ e)
     26      (let ()
     27        (define/with-syntax whole
     28          (local-expand #'(let-values ([(e) 2]) e) 'expression '()))
     29        (define/with-syntax (_ _ xx) #'whole)
     30        #'(let-values ([(xx) xx])
     31            (list xx
     32                  whole)))]))
     33 
     34 ;; This does produce an error. The xxx must not be used as an expression.
     35 #;(let ([x 1])
     36     (test2 x))