I think the following program illustrates the idea, though it doesn't
really work:
#lang racket
(begin-for-syntax
(define (syntax-pair->cons stx)
(define datum (syntax-e stx))
(cond
[(list? datum)
(map syntax-pair->cons datum)]
[(pair? datum)
(cons (syntax-pair->cons (car datum))
(syntax-pair->cons (cdr datum)))]
[else stx]))
(define (ir-macro-transformer proc)
(lambda (stx)
(define transformed-s-expr
(proc (syntax-pair->cons stx)
(λ (id) (datum->syntax stx id))))
(datum->syntax #'here transformed-s-expr)))) ;; hack
(define-syntax loop
(ir-macro-transformer
(lambda (expr inject)
(let ((body (cdr expr)))
`(call-with-current-continuation
(lambda (,(inject 'exit))
(let f () ,@body (f))))))))
(let ([i 0])
(loop
(printf "i = ~a\n" i)
(set! i (+ i 1))
(when (>= i 5)
(exit 'ok))))
Syntax objects are the representation of syntaxes used in expansion
and compilation. Racket doesn't just use quoted expressions since the
expander and the compiler need to keep track of lexical information,
source location and other properties. The form #' and #` are
constructors of syntax objects that take templates and produce the
syntax objects with the desired shape, just like ' and ` are
constructors of quoted s-expressions.
If you want to provide a function that manipulates lists and symbols
as a transformer, ir-macro-transformer would at least need to be a
function that maps between syntax objects and quoted expressions. Such
maps are imperfect though.
One problem I found with the above program is that `inject' doesn't
have the desired lexical context, so the while example does not work.
phase 1 phase 0
+------------ syntax object (instead of quoted s-expression)
|
transformer
(lambda functions bound
using define-syntax)
|
+-----------> syntax object