Welcome to the CHICKEN Scheme pasting service

Visibility of define-for-syntax in a module pasted by jcroisant on Sun Aug 24 08:09:55 2025

;;; Variables that are define-for-syntax'd inside a module are not
;;; visible to eval inside macro calls in the module. But it works
;;; outside a module.

(module m (print-syntax-var)
  (import scheme (chicken syntax))

  (define-syntax print-syntax-var
    (ir-macro-transformer
     (lambda (form inject compare)
       (print (eval (cadr form)))
       #f)))

  (define-for-syntax foo (* 21 2))

  ;; unbound variable: m#foo
  (print-syntax-var foo)                ; <--------
  )


(import m)

(define-syntax print-syntax-var2
  (ir-macro-transformer
   (lambda (form inject compare)
     (print (eval (cadr form)))
     #f)))

(define-for-syntax bar (+ 121 2))

;; But this works
(print-syntax-var2 bar)                 ; <--------

;; Even this works
(print-syntax-var bar)                  ; <--------

One way to define data variables and pass them to macros added by jcroisant on Sun Aug 24 10:41:22 2025

;; in data.scm

(module data (foo bar)
  (import scheme)
  (define foo (* 21 2))
  (define bar (+ 121 2)))


;; in macros.scm

(module macros (print-syntax-var)
  (import scheme (chicken syntax))

  (define-syntax print-syntax-var
    (ir-macro-transformer
     (lambda (form inject compare)
       (print (eval (cadr form)))
       #f))))


;; in lib.scm

(module lib ()
  (import scheme
          macros
          data)

  (import-for-syntax data)

  (print-syntax-var foo)
  (print-syntax-var bar))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the language CHICKEN compiles to:
Visually impaired? Let me spell it for you (wav file) download WAV