Interaction with a reader in scribble

Hi,

is it possible to use interaction in scribble with a reader?, example of what i mean:

#lang scribble/manual
@(require scribble/core)
@(require scribble/eval)

@interaction[
#lang reader SRFI-105
(require Scheme+)
{3 · 5 + 2 ³}
]

the above example will not parse and use #lang reader SRFI-105 correctly and will fail compiling the document.

1 Like

Does the examples form from scribble/example` work?

I honestly don’t know this at all - I just noticed that the docs suggest the scribble/example library should be used instead of scribble/eval.

Regards
Stephen

thank for your help Stephen, i tested the sole example of the doc and it does not seems to accept a reader,only a module as racket/base.

This is a bit the problem of Racket, i often encounter, the #lang language or #lang reader program that is so far from sexpr that it could not be used in any context. In fact #lang language could be replaced by (module program-name language... but there is no equivalent for #lang reader a-reader or #reader a-reader could not be represented as a sexpr module.

I can not find a solution and i do not think it is possible in Racket.

Damien

1 Like

I don't have all the answers but I have some leads you might want to follow.

It looks like you're not supplying an evaluator to interaction (using its #:eval argument).

The docs say interaction works the same as examples (from scribble/example) with a few minor changes, so check the docs for examples.

The docs for examples say you can supply your own evaluator, defined using make-evaluator.

I recommend reading the docs for make-evaluator carefully. Yes they are complicated at first glance but if you want to be doing advanced things with eval'd code this is where the advanced functionality is described in detail.

In particular those docs say that if you supply code to the evaluator as a string or an input port, the code will be read using the function currently stored in the sandbox-reader parameter. If you can access the binding for whatever the equivalent of syntax-read is for your #lang, you can probably use it with this parameter.

1 Like

yes i will take a look at that. I have sort of syntax-read of course in the code of SRFI-105, if i find a way to import that in a scribble document,why not?
for now i just use codeblock directives , in my scribble.
It is amazing i got the idea when i see that when compiling scribble pages to html the system was evauating some expression in codeblock as if the scribble document was code...

i will get back on these possibility later
thank

i can not find where to use (sandbox-reader proc)
i read all the doc but it lacks examples.

The docs don't always have examples of everything one might want to attempt. In such cases there's no choice but to buckle down and not scan for code to use but thoroughly understand the concepts involved. In this case I was able to cobble this together just by squinting at the docs and trying stuff in DrRacket. I already have an understanding of how to use parameters, which helped quite a bit.

#lang scribble/manual

@(require racket/sandbox
         scribble/reader
         scribble/eval)

@(define r (make-at-reader #:inside? #t))
@(define (my-syntax-read in) (syntax-e (r in)))

@(define my-evaluator
  (parameterize ([sandbox-reader my-syntax-read])
    (make-base-eval)))
@(my-evaluator "@require[racket/format]")
@(my-evaluator "@define[(foo v)]{@~a{here's @v !}}")

@interaction[#:eval my-evaluator]{
 @foo{Johnny}
}

Note that even though the code I give to interaction is in a non-s-expression syntax, interaction will always typeset it as an S-expression. Which makes sense because the REPL is always using S-expressions anyway. Here's the HTML rendered result of the above program:

1 Like

Thank you for your help Joel.

The thing is not easy.

I find a racket discourse post with the same problem that was talking of a solution using a third party library, i suppose this library exists because things are hard. I used scribble-code-example library.

and inserted in my doc this :

@(require scribble-code-examples)

@code-examples[#:lang "reader SRFI-105" #:context #'here]|{
{11 + 2}
}|

this times , the library accepts the `#lang reader SRFI-105" and the result is:

Capture d’écran_2025-11-20_18-00-31

about your solution, i still have dificulties, some hard points are you seem to use make-base-eval but i must write a special evaluator for infix, also i can not rely on the REPL using only sexpr because in my case i use curly infix expressions starting with { }.

Perheaps you can find a solution with your knowledge if i give you the things special to my case but otherwise i will use the third party lib:

in my case there a few points to specialize:

  • somewhere there should be #lang reader SRFI-105 or #reader SRFI-105 as Racket accept both forms
  • in the use by scribble of my SRFI-105 reader the sandbox-reader i suppose must be set to the one defined in my reader , which by convention for racket REPL is read-syntax but if it is a convention why should we specified it? here is my module definition of SRFI-105:
 (module SRFI-105 racket
	

      (provide (rename-out [literal-read read]
                           [literal-read-syntax read-syntax]))

litteral-read-syntax are defined using curly-infix-read one does not have to know this internal definition.
As it is a convention i suppose that there is no need to specify it in code-examples, or perheaps the library sends the tokens to the reader and just get the result,i do not know.

Unless you have a solution according with this few specifications , i will use code-examples one as it is the only one that works for now.

Again, Joel, thank you for your help.
Sincere thanks
Damien