Here is a variant of the program that asserts a phase level and breaks if it is 
not the expected one. This is just a programmatic confirmation of Alexis’s 
explanation of course. 


#lang racket


(module syntax-assertions racket 
  (provide assert-level)
  (define (assert-level i)
    (define observed
      (- (variable-reference->phase (#%variable-reference))
         (variable-reference->module-base-phase (#%variable-reference))))
    (unless (= i observed)
      (raise-syntax-error #f (format "expected phase level: ~a, actual phase 
level ~a" i observed)))))

(require (for-syntax (submod "." syntax-assertions)))

;; 
---------------------------------------------------------------------------------------------------


(module utilities racket/base
  (require (submod ".." syntax-assertions))
  
  (provide compile-test)

  (define (compile-test)
    (assert-level 1) ;; <— you want to run at this level 
    #`(lambda (i) (displayln `(input: ,input)))))

(require (for-syntax 'utilities))

(define-syntax (this-works stx)
  (syntax-case stx ()
    ((_ input)
     (let ()
       (define (compile-test)
         (assert-level 1) ;; <— you want to run at this level 
         #`(lambda (i) (displayln `(input: ,input))))

       #`(#,(compile-test) input)))))

(define-syntax (this-does-not-work stx)
  (syntax-case stx ()
    ((_ input to-do ...)
     (let ()

       #`(#,(compile-test) input)))))

(this-works 3)
(this-does-not-work 3)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to