Suppose I want to return lexically scoped syntax from a defined function, e.g. like this:
(define (a x)
(define (b y) (* y x))
(define h (make-hash))
(set! h 'b b)
(define-syntax caller
(syntax-rules ()
((_ i . args)
(apply (hash-ref h 'i) args))))
caller)
This doesn't work, it gives an error:
. caller: bad syntax in: caller
However:
> (define h (make-hash))
(hash-set! h 'f (lambda (x) (* x x)))
> (define-syntax appl
(syntax-rules ()
((_ f)
(f ()))
((_ f (a ...))
(f a ...))))
> (define-syntax caller
(syntax-rules (h)
((_ i . args)
(let ((f (hash-ref h 'i)))
(appl f args)))))
> (caller f 5)
25
Seems to be a valid construct.