[racket] Installing a reader macro in Scribble

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jan 8 18:05:59 EST 2013

At Tue, 8 Jan 2013 16:02:28 -0600, Grant Rettke wrote:
> Hi,
> 
> I have a first goal of loading a file into an @interaction block in
> side of Scribble.
> 
> The language to evaluate those values is another story, I just want to
> get the contents of a file in there. Here is what I have done:
> 
> ; the file to load
> ; cat 04-02.clp
> (watch all)
> (reset)
> (defrule do-anything
>   "A rule for anything."
>   ?ne <- (anything)
>   =>
>   (printout t "Someone did something.")
>   (retract ?ne))
> (assert (anything))
> (run)
> 
> ; the reader macro
> ; cat 06-04.rkt
> #lang racket
> 
> (require racket/port)
> 
> (provide read read-syntax)
> 
> (define (read in) (work in))
> (define (read-syntax src in) (work in))
> 
> (define (work in)
>   (let* ((path (first (port->lines in)))
>          (in (open-input-file path #:mode 'text)))
>     (port->string in)))
> 
> ; a sample program that works
> cat 06-04a.rkt
> #lang racket
> 
> #reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp
> 
> ; a scribble that does not work
> cat 06-05.scrbl
> #lang scribble/manual
> 
> @title{Basic Scribble External Eval}
> 
> @(require scribble/eval
>           racket/sandbox)
> 
> @(define my-evaluator
>    (parameterize ([sandbox-output 'string]
>                   [sandbox-error-output 'string])
>      (make-evaluator 'racket)))
> 
> @interaction[#:eval
>              my-evaluator
>              (display "Hello, world.")]
> 
> #reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp
> 
> ;; end
> 
> I do need to load that file into the @interaction block, but didn't
> set it up yet not to lose the closing square paren.
> 
> Scribble just renders
> "#reader"06-04.rkt"/home/gcr/racket-external-eval/04-02.clp" instead
> of doing what it did in Racket.

The `#' character is not an escape character in Scribble. It's treated
as literal text, just like the letter "a" or a comma.

Does simply adding the escape character `@' in front of `#reader' do
what you want?


Posted on the users mailing list.