Macros appear to ignore the (provide) declaration in a module in the case of a syntax-rules macro, and creates an error in the case of the syntax-case macro.
Here is an example file (test_loading.scm):
(provide what)
(define what "what")
(define the "the")
(define-syntax hi!
(syntax-rules ()
((_) (print "hello world"))))
(define-syntax subset!
(lambda (stx)
(syntax-case stx ()
((_ df)
(error "Did you forget to add a subset expression?"))
((_ df string)
(begin
(if
(string? (syntax->datum #'string))
#'(error string)
(symbol->string (syntax->datum #'(string))))
))
((_ df cond ...)
(symbol->string (syntax->datum #'(cond ...))))
)))
When I require this module in the repl (require "test_loading.scm"), I have access to the variable what, and I don't have access to the variable the (as expected). However, I can call (hi!) and (subset!) just fine even though they aren't in the (provide) declaration. If I put the subset! macro in the provide delcaration, I get this error when I require the module:
error[E02]: FreeIdentifier
┌─ /home/david/Documents/Personal-Projects/piper/examples/test_loading.scm:2:3
│
2 │ subset!)
│ ^^^^^^^ Cannot reference an identifier before its definition: subset!
If I put hi! in the provide declaration, nothing seems to happen at all. I can call (hi!) fine.
Also, this might deserve its own issue, but errors thrown within the syntax-case macro are not reported correctly, for example, the above subset! macro will throw an error if it recieves a string as the second argument:
λ > (subset! metadata "hi")
Unable to locate source and span information for this error: Error: Generic: hi
Macros appear to ignore the
(provide)declaration in a module in the case of asyntax-rulesmacro, and creates an error in the case of thesyntax-casemacro.Here is an example file (
test_loading.scm):When I require this module in the repl
(require "test_loading.scm"), I have access to the variablewhat, and I don't have access to the variablethe(as expected). However, I can call(hi!)and(subset!)just fine even though they aren't in the(provide)declaration. If I put thesubset!macro in theprovidedelcaration, I get this error when I require the module:If I put
hi!in theprovidedeclaration, nothing seems to happen at all. I can call(hi!)fine.Also, this might deserve its own issue, but errors thrown within the
syntax-casemacro are not reported correctly, for example, the abovesubset!macro will throw an error if it recieves a string as the second argument: