For Development HEAD DRAFTSearch (procedure/syntax/module):

5.8 Macro utilities

Macro: syntax-error msg arg …
Macro: syntax-errorf fmt arg …

Signal an error. They are same as error and errorf (see Signaling exceptions), except that the error is signaled at macro-expansion time (i.e. compile time) rather than run time.

They are useful to tell the user the wrong usage of macro in the comprehensive way, instead of the cryptic error from the macro transformer. Because of the purpose, arg … are first passed to unwrap-syntax to strip off the internal syntactic binding informations (see Identifiers).

(define-syntax my-macro
  (syntax-rules ()
    ((_ a b)   (foo2 a b))
    ((_ a b c) (foo3 a b c))
    ((_ . ?)
     (syntax-error "malformed my-macro" (my-macro . ?)))))

(my-macro 1 2 3 4)
  ⇒ error: "malformed my-macro: (my-macro 1 2 3 4)"

Note: In the er-macro-expander, you can use the ordinary error procedure to report wrong macro usage. The body of the expander is evaluated at the macro expansion time, so the error is raised then. syntax-error is needed for syntax-rules, since it is just inserted (not evaluated) into the expanded form at the macro expansion time, and only evaluated at runtime.



For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT