laurent.orseau
2021-7-11 11:53:40

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?


massung
2021-7-11 11:58:01

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


massung
2021-7-11 11:58:19

But not #,`.


sorawee
2021-7-11 12:00:13

You might want to use #:escape


laurent.orseau
2021-7-11 12:01:42

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


laurent.orseau
2021-7-11 12:02:14

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


laurent.orseau
2021-7-11 12:02:50

#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"


massung
2021-7-11 12:03:20

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


laurent.orseau
2021-7-11 12:04:03

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


laurent.orseau
2021-7-11 12:07:45

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


sorawee
2021-7-11 12:11:44

What are you trying to do though?


sorawee
2021-7-11 12:11:52

Make ev evaluates require?


sorawee
2021-7-11 12:12:04

You can also do:

(ev `(require ,@mods))


sorawee
2021-7-11 12:12:06

I think


sorawee
2021-7-11 12:12:32

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


laurent.orseau
2021-7-11 12:13:36

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


laurent.orseau
2021-7-11 12:14:28

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


laurent.orseau
2021-7-11 12:15:49

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)


laurent.orseau
2021-7-11 12:56:33

@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?


laurent.orseau
2021-7-11 12:58:41

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


rokitna
2021-7-11 12:58:58

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


laurent.orseau
2021-7-11 13:00:36

yes, examples works just fine otherwise


rokitna
2021-7-11 13:02:13

oops, I was far behind on the conversation, sorry


laurent.orseau
2021-7-11 13:03:02

np!


laurent.orseau
2021-7-11 13:11:14

I filed a report.


ben.knoble
2021-7-11 14:19:23

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


laurent.orseau
2021-7-11 14:24:40

Indeed, it’s only with #lang racket


shu--hung
2021-7-11 19:38:06

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


laurent.orseau
2021-7-11 21:42:16

Is there a way to detect this case maybe?


greg
2021-7-11 23:52:03

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


greg
2021-7-11 23:53:11

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?”.


greg
2021-7-11 23:54:44

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


greg
2021-7-11 23:59:30

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))”?


laurent.orseau
2021-7-12 06:55:53

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.