mac-mod.scm: ----- (module mac-mod (definer user) (import chicken scheme) (use-for-syntax matchable) (define-syntax definer (ir-macro-transformer (lambda (stx inject compare) (match stx ((definer NAME) (let* ((NAME* (inject NAME)) (NAME* (strip-syntax NAME)) (syntax-NAME* (symbol-append 'syntax- NAME*))) `(begin (define-for-syntax ,syntax-NAME* "my-object-at-syntax-time") (define ,NAME* "my-object-at-run-time")))))))) (define-syntax user (ir-macro-transformer (lambda (stx inject compare) (match stx ((user NEW-NAME OLD-NAME) (let* ((NEW-NAME* (inject NEW-NAME)) (NEW-NAME* (strip-syntax NEW-NAME)) (syntax-NEW-NAME* (symbol-append 'syntax- NEW-NAME*)) (OLD-NAME* (inject OLD-NAME)) (OLD-NAME* (strip-syntax OLD-NAME)) (syntax-OLD-NAME* (symbol-append 'syntax- OLD-NAME*)) (object (eval syntax-OLD-NAME*))) `(begin (define-for-syntax ,syntax-NEW-NAME* ,syntax-OLD-NAME*) (define ,NEW-NAME* ,OLD-NAME*)))))))) ) ;;; csc -feature compiling-extension -setup-mode -s -d2 mac-mod.scm -j mac-mod ;;; csc -feature compiling-extension -setup-mode -s mac-mod.import.scm -d0 ;;; csc -feature compiling-extension -setup-mode -c -d2 mac-mod.scm -unit mac-mod -j mac-mod ----- mac-prog.scm: ----- (use mac-mod) (definer thingy) (printf "Got ~S at run-time\n" thingy) (begin-for-syntax (printf "Got ~S at compile-time\n" syntax-thingy)) (user new-thingy thingy) (printf "Got ~S at run-time\n" new-thingy) (begin-for-syntax (printf "Got ~S at compile-time\n" syntax-new-thingy)) ;;; csc mac-prog.scm ----- mac-prog-mod.scm ----- $ more mac-prog-mod.scm (module mac-prog-mod () (import chicken scheme) (use mac-mod) (definer thingy) (printf "Got ~S at run-time\n" thingy) (begin-for-syntax (printf "Got ~S at compile-time\n" syntax-thingy)) (user new-thingy thingy) (printf "Got ~S at run-time\n" new-thingy) (begin-for-syntax (printf "Got ~S at compile-time\n" syntax-new-thingy)) ) ;;; csc mac-prog-mod.scm ;;; csc -feature compiling-extension -setup-mode -s -d2 mac-prog-mod.scm -j mac-prog-mod ;;; csc -feature compiling-extension -setup-mode -s mac-prog-mod.import.scm -d0 ;;; csc -feature compiling-extension -setup-mode -c -d2 mac-prog-mod.scm -unit mac-prog-mod -j mac-prog-mod ----- Compile the module: $ csc -feature compiling-extension -setup-mode -s -d2 mac-mod.scm -j mac-mod $ csc -feature compiling-extension -setup-mode -s mac-mod.import.scm -d0 $ csc -feature compiling-extension -setup-mode -c -d2 mac-mod.scm -unit mac-mod -j mac-mod Compile the program that uses the module in the top-level: $ csc mac-prog.scm Compile the module that uses the module: $ csc mac-prog-mod.scm -> ----- Got "my-object-at-syntax-time" at compile-time Error: during expansion of (user ...) - unbound variable: mac-prog-mod#syntax-thingy Call history: (##core#set! thingy19 "my-object-at-run-time") (printf "Got ~S at run-time\n" thingy) (##core#let ((out28 ##sys#standard-output)) (##sys#check-output-port out28 #t (quote printf)) (##sys...... (##core#begin (##sys#check-output-port out28 #t (quote printf)) (##sys#print "Got " #f out28) (##sys...... (##sys#check-output-port out28 #t (quote printf)) (quote printf) (##core#quote printf) (##sys#print "Got " #f out28) (##sys#print thingy #t out28) (##sys#print " at run-time\n" #f out28) (begin-for-syntax (printf "Got ~S at compile-time\n" syntax-thingy)) (##core#elaborationtimeonly (##core#begin (printf "Got ~S at compile-time\n" syntax-thingy))) (##core#begin (printf "Got ~S at compile-time\n" syntax-thingy)) (printf "Got ~S at compile-time\n" syntax-thingy) (printf "Got ~S at compile-time\n" syntax-thingy) (user new-thingy thingy) <-- Error: shell command terminated with non-zero exit status 17920: '/usr/local/chicken-4.9.0/bin/chicken' 'mac-prog-mod.scm' -output-file 'mac-prog-mod.c' -----