[racket] Help: Scribble does not see readtable extensions when loading a module

From: Maurizio Giordano (maurizio.giorda at gmail.com)
Date: Wed Jun 29 06:54:24 EDT 2011

Hi Carl, Matthias and Eli,

first of all I want to thank you for your help.
You are very skilled schemers ... compared to me!
I left lisp in 1995 (my thesis work) an now I restarted
with racket scheme (it's never too late!).

Anyway I followed Carl's 1st solution:

1) put a #reader directive before the (example) code in question

It has been easier for me to define a new reader in a module and
to load the reader extensions with the #reader directive.

My solution was the following code:

@examples[
     #reader"msetreader.rkt"   ; my new reader
     (require hocl)            ; my module implementing the new language
     (make-mset #(1 2 3 4))
     (define t2 < 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 >) 
     t2
   ]

and it works. The web page output is:

> (require hocl)
> (make-mset #(1 2 3 4))        
<1, 2, 3, 4>
> (define t2 (make-mset (vector 1  2  3  4  5  6  7  8  9  10  11))
> t2
<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11>

In fact, "(make-mset (vector ...))" is the macro expansion
generated by my reader when parsing <...> syntax.
Nevertheless, now the <...> forms are correctly read, by I don't want
the "macro-expansion" result be printed in the web page... Do you have
any suggestions?
  
About Carl's 2nd solution:
 
2) (set the new) reader for the entire Scribble document 
   by changing #lang line

I am sure this solution will also work. To do that I have
to change my module in such a way it defines a new language
implementation.
I will do that in a future... if my new (chemical) language 
project will go on.

About Carl's 3rd solution:

3) build the example code at runtime by reading from a string

This solution is not clear to me.

If you want to know more about the chemical language implementation
in scheme, I will be glad give you more details and documentation.

Thank you,

Maurizio Giordano


On Mon, 2011-06-27 at 15:37 -0400, Matthias Felleisen wrote:
> What Carl means is something like this: 
> 
> @;%
> @(begin
> #reader scribble/comment-reader
> (schemeblock
>  ;; Int -> Int 
>  ;; increment the argument by 1
>  (define (plus1 x) (+ x 1))
> ))
> @;%
> 
> If I don't set the sribble/comment-reader the ;-line comments disappear. 
> 
> -- Matthias
> 
> 
> 
> 
> On Jun 27, 2011, at 3:32 PM, Carl Eastlund wrote:
> 
> > Maurizio,
> > 
> > Modules, including Scribble documents, are read in their entirety
> > before any compilation or evaluation is performed.  The read error you
> > have seen happens long before your mymodule language gets involved.
> > There are a few different ways to fix the example.  First, you could
> > put a #reader directive before the code in question, so your <...>
> > syntax would be used there.  Second, you could use your <...> reader
> > for the entire Scribble document by changing your #lang line.  This
> > probably requires a new language implementation similar to #lang s-exp
> > that specifies the reader but allows you to specify any language
> > bindings, in this case scribble/manual.  Third, you could build the
> > example code at runtime by reading from a string.
> > 
> > Carl Eastlund
> > 
> > On Mon, Jun 27, 2011 at 12:17 PM, maurizio.giorda
> > <maurizio.giorda at gmail.com> wrote:
> >> Hi everyone,
> >> 
> >> I have developed a racket module that implements a new
> >> language. In this module I have readtable re-definition like this:
> >> 
> >> ------------mymodule.rkt---------------------
> >> (module mymodule
> >> (require racket/base)
> >> ...
> >> ; new readtable with extensions to support the reading of a new
> >> ; data structure: "mset" is a tuple of elements, like < 1, 2, 3 >
> >> (define mset-readtable
> >>      (make-readtable #f #\< 'terminating-macro parse-open-mset ))
> >> 
> >> ; change the reader to support my new data structure "mset"
> >> (current-readtable mset-readtable)
> >> ...
> >> )
> >> ----------------------------------------------------
> >> 
> >> Now I am trying to write documentation for this module with scribble.
> >> When I use the @interaction in the followign way:
> >> 
> >> ------------mymodule.scrbl---------------------
> >> #lang scribble/manual
> >> @(require scribble/eval)
> >> ...
> >>  @interaction[
> >>     (require mymodule)
> >>     (make-mset #(1 2 3 4))
> >>     (define t2 < 1, 2, 3, 4 >)
> >>   ]
> >> ...
> >> -------------------------------------------------------
> >> 
> >> I got this in the produced documetation web page:
> >> --------------------------------------------------------
> >>> (require mymodule)
> >>> (make-mset #(1 2 3 4))
> >> <1, 2, 3, 4>
> >>> (define t2 < 1,2,3,4 >)
> >>  eval:3:0: define: bad syntax (multiple expressions after
> >>  identifier) in: (define t2 < 1 (unquote 2) (unquote 3)
> >>  (unquote 4) >)
> >> --------------------------------------------------------
> >> 
> >> "make-mset" is my data structure constructor function, and it works
> >> (you see the printout on the 3rd line),
> >> but the same constructor should be called by the reader when
> >> processing the "< 1, 2, 3, 4 >" input.
> >> So my conclusion is that, for some reasons, the scribble
> >> reader have not set my readtable extensions.
> >> Does anyone know what is wrong?
> >> 
> >> Maurizio Giordano
> >> 
> >> PS: I also tried using @eval[...]
> >> with a sandbox evalutator defined by me with
> >> the "required" module loaded into it... but it gives
> >> me the same result.
> > 
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://lists.racket-lang.org/listinfo/users
> 




Posted on the users mailing list.