Reputation: 22460
According to DrRacket Docs, the syntax-violation
form is defined in rnrs/syntax-case-6
. But I'd like to use the syntax-case
from racket/base
and avoid importing rnrs/syntax-case-6
(and r6rs in general since it seems to have a different syntax-case
implementation than the racket/base
).
Is there another function from racket/base
or racket/racket
that can replace syntax-violation
? Or, should I write my own version that raises an exception?
--Edit--
I tried to import syntax-violation
from racket/base
, but it seems to be missing from there:
racket
Welcome to Racket v8.6 [cs].
> syntax-violation
syntax-violation: undefined;
cannot reference an identifier before its definition
in module: top-level
[,bt for context]
> (require racket/base)
> syntax-violation
syntax-violation: undefined;
cannot reference an identifier before its definition
in module: top-level
[,bt for context]
> (syntax-violation #f "error message" #f)
syntax-violation: undefined;
cannot reference an identifier before its definition
in module: top-level
[,bt for context]
Upvotes: 0
Views: 49
Reputation: 52334
I use raise-syntax-error
in macro error handling, which raises an exception of type exn:fail:syntax
. From the docs:
Macros use this procedure to report syntax errors.
Example:
(define-syntax (example stx)
(syntax-case stx ()
((_) (raise-syntax-error 'example "no arguments" stx))
((_ x) #'(do-something-with x))))
Upvotes: 1
Reputation: 6502
You can use raise-syntax-error
directly.
Internally, syntax-violation
is implemented in Racket by using raise-syntax-error
.
Upvotes: 1