Previous: , Up: Macros   [Index]


4.3.3 Signaling errors in macro transformers

syntax: syntax-error ⟨message⟩ ⟨args⟩…

syntax-error behaves similarly to error (Exceptions) except that implementations with an expansion pass separate from evaluation should signal an error as soon as syntax-error is expanded. This can be used as a syntax-rules ⟨template⟩ for a ⟨pattern⟩ that is an invalid use of the macro, which can provide more descriptive error messages. ⟨message⟩ is a string literal, and ⟨args⟩ arbitrary expressions providing additional information. Applications cannot count on being able to catch syntax errors with exception handlers or guards.

(define-syntax simple-let
  (syntax-rules ()
    ((simple-let ((x . y) val) body1 body2 ...)
     (syntax-error "expected an identifier" (x . y)))
    ((simple-let (name val) body1 body2 ...)