[plt-scheme] #%top experiment
I'm making my first attempt at using #%top. With this module, I'd like all code
to evaluate normally, except that when an undefined symbol is encountered, I'd
like to search *hash* for it before signalling an error:
(module hasher mzscheme
(define *hash* (make-hash-table))
(hash-table-put! *hash* 'test 'ok)
(provide (rename top #%top))
(define-syntax (top stx)
(syntax-case stx ()
((_ . identifier)
(let ((s (syntax-e #'identifier)))
(if (symbol? s)
(syntax/loc stx
(if (not (namespace-variable-value 'identifier #f (lambda () #f)))
(hash-table-get *hash* 'identifier (lambda () (error 'identifier "not defined")))
(#%top . identifier)))
(syntax/loc stx (#%top . identifier))))))))
(This is lifted from similar code in swindle.ss in the swindle collection.)
This code works
(require hasher
(define x 1)
(display x) ;; 1
(display test) ;; ok
)
However, when I go to something a little more complex it breaks:
(require hasher)
(require (lib "whatever.ss" "somewhere"))
This gets the error "lib: not defined". Clearly I need a more sophisticated test in
the syntax. Any suggestions?
Wayne