
Here’s a minimal failing example: #lang racket
(require scribble/example)
(define ev (make-base-eval))
(define mods '(racket/string racket/list))
(examples #:eval ev
#,`(require ,@mods))
;; fails with:
;; examples: exception raised in example
;; error: "unsyntax: illegal outside of quasisyntax"
I believe this follows what the docs for <https://docs.racket-lang.org/scribble/eval.html?q=examples#%28form._%28%28lib._scribble%2Fexample..rkt%29._examples%29%29\|examples>
say. Am I missing something or should I file a bug?

Isn’t it #
(require ,@mods)?
For example:
(define mods (list #'1 #'2 #'3))
#`(require ,@mods) ;=> #<syntax:3-unsaved-editor:3:2 (require (unquote-splicing mods))>
#`(require #,@mods) ;=> #<syntax:3-unsaved-editor:3:2 (require 1 2 3)>
`

But not #,
`.

You might want to use #:escape

Thanks, but unfortunately it’s a little trickier than that. I need to escape from examples, and #,
is (ab)used to have that meaning in examples
. With #
(require ,@mods,
examples` will evaluate the syntax form, as a syntax object. I want it to evaluate the s-expr thing

I tried that, see my message a little above this one. Couldn’t make it work either

#lang racket
(require scribble/example)
(define ev (make-base-eval))
(define mods '(racket/string racket/list))
(examples #:eval ev #:escape WOO
(WOO `(require ,@mods)))
(examples #:eval ev (first '(a b c)))
;; fails with:
;; examples: exception raised in example
;; error: "unsyntax: illegal outside of quasisyntax"

Ah ok. I figured there was something… Special going on, but it was unclear so I figured I’d make sure. :wink:

Thanks for helping out! I often miss the simple and obvious, so checks like these are a necessity with me :wink:

Aha! At least I can use this work-around: ((scribble-eval-handler)
ev
#f
`(require ,@mods))

What are you trying to do though?

Make ev
evaluates require
?

You can also do:
(ev `(require ,@mods))

I think

That’s how I usually require stuff at the beginning of a document

I tried that too, but there’s some important stuff going on with the scribble thing, in particular output parameterization and all

so it was becoming annoying to tackle all the cases manually, in particular since it’s already done by something in scribble. scribble-eval-handler
was just the hook I was looking for

top-level forms like require
to be displayed in the examples is also trickier to handle manually, in particular if you want to wrap the calls inside the expression (which you cannot because require
needs to be at the top level)

@sorawee I think you have some bug reports or PRs maybe related to poor error messages? Here’s an annoying one: #lang racket/base
(require syntax/parse/define
#;(for-syntax racket/base))
(define-syntax-parse-rule (foo x)
#:with y #'x
(list y))
highlights #'
and throws: syntax: unbound identifier;
also, no #%app syntax transformer is bound in the transformer phase in: syntax
Do you have a particular place where I should add this one, or should I just file a report directly?

Uncommenting (for-syntax ...)
solves the issue

is examples
in scope? looks like this error is the kind you could get if you didn’t import it

yes, examples
works just fine otherwise

oops, I was far behind on the conversation, sorry

np!

I filed a report.

I thought racket/base was already available for-syntax? Or is that only in #lang racket
and not racket/base?

Indeed, it’s only with #lang racket

This is one case where I agree that the error message is cryptic, but one that I don’t know what could be a sensible fix

Is there a way to detect this case maybe?

It’s exacerbated by the error message talking about syntax
which doesn’t appear in your source (as opposed to the reader #'
).

Plus, maybe unique to me, at the time I first encountered this, I was struggling a bit with “syntax zoo” and I think I kept reading “syntax” generically as opposed to syntax
— “you have an error in your syntax”, “OK well sure but what exactly?”.

So it’s kind of a perfect storm for confusion. :slightly_smiling_face:

As to how the error message could be improved: Am I correct that define-syntax
itself, or the expander itself, would need to do this? (“this” = something like append to the existing error message some hint like “Maybe you need to (require (for-syntax racket/base))
”?

In particular when the error message already contains “also no app transformer is bound…” which may be technically correct, but probably not very helpful to almost everyone, I bet.