[racket] scribble/lp: comments stripped, how to stop?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Apr 23 20:00:07 EDT 2012


Some more investigation: 

If you remove the hack mentioned below, your comments in chunks disappear: 

#lang scribble/lp

Literate programs have chunks of code, like this one:

@chunk[<f>
       (define (f x)
         ;; hello world disappears 
         <fs-body>)]

and this one:

@chunk[<fs-body>
       (* x x)]

that, when assembled, produce a complete program, in this case:

@racketblock[(define (f x)
               (code:comment "hello") 
               (* x x))]


That is code:comment works as expected. The code also works when run: 

> Welcome to DrRacket, version 5.3.0.2--2012-04-20(25d7d49/g) [3m].
> Language: scribble/lp.
> > (f 10)
> 100

I am not sure whether this is what you want but that's all I can figure out. 
From what I can tell, LP parses the module (via expand), extracts chunks 
and compiles them into a complete program. In the process all comments
go away. 

The extra code appears to come from me but I have never actually worked
on LP or used it so this will remain a mystery to me. Apologies 

-- Matthias




On Apr 23, 2012, at 2:44 PM, Deren Dohoda wrote:

> I've never gotten into anything but trivial syntax operations. I'd be happy to dig further if anyone can get me started on stepping though expansions of included files. Sounds like a good learning opportunity.
> On Apr 22, 2012 3:34 PM, "Matthias Felleisen" <matthias at ccs.neu.edu> wrote:
> 
> I haven't used /lp myself. I am stuck here -- Matthias
> 
> 
> 
> On Apr 22, 2012, at 12:25 AM, Deren Dohoda wrote:
> 
> > Hi Matthias,
> >
> > I cannot seem to get it to work. I can get scribble to be happy, but
> > not the scribble/lp file.
> >
> > First try: (somewhere in the middle of the file)
> > @(begin
> >   #reader scribble/comment-reader
> >   (chunk <hs-from-xs>
> >          (define hs ; (xi+1) - xi
> >            (map - (rest xs) (drop-right xs 1)))))
> > Second try:
> > @chunk[<hs-from-xs>
> >       #reader scribble/comment-reader
> >       (define hs ; (xi+1) - xi
> >         (map - (rest xs) (drop-right xs 1)))]
> >
> > Both can be scribbled with the comment when included with (lp-include
> > ...), but doesn't run when one runs the file itself. When the file is
> > run, this error appears: "bad syntax (multiple expressions after
> > identifier) in: (define hs (code:comment ..." The only place I can
> > find code:comment defined is in
> > "...Racket/collects/scribble/lp/lang/lang.rkt":
> > (provide code:comment)
> > (define-syntax (code:comment stx)
> >  (if (eq? (syntax-local-context) 'expression)
> >      (syntax (void))
> >      (syntax (define (f x) x))))
> >
> > It looks like it was supposed to strip the comment when being run.
> > "...Racket/collects/scribble/comment-reader.rkt" does have
> >
> > (define (do-comment port recur)
> >    (let loop ()
> >      (when (equal? #\; (peek-char port))
> >        (read-char port)
> >        (loop)))
> >    (when (equal? #\space (peek-char port))
> >      (read-char port))
> >    `(code:comment
> >      (unsyntax ...
> >
> > So it seems like this is where code:comment is coming from, but for
> > some reason the code:comments rule from lang.rkt isn't seeing it.
> >
> > Deren
> >
> > On Sat, Apr 21, 2012 at 9:07 PM, Matthias Felleisen
> > <matthias at ccs.neu.edu> wrote:
> >>
> >> Do you use
> >>
> >> @;%
> >> @(begin
> >> #reader scribble/comment-reader
> >> (racketblock
> >> (place-image ROCKET X ... MTSCN)
> >> ))
> >> @;%
> >>
> >> to write down code blocks? It installs a reader that can cope with comments.
> >>
> >>
> >>
> >> On Apr 21, 2012, at 4:53 PM, Deren Dohoda wrote:
> >>
> >>> I have finally started learning scribble for use in literate
> >>> programming to break away from noweb for Racket. It's quite excellent,
> >>> I am glad to be making the switch. Thank everyone for their work. I
> >>> miss the math of latex but it isn't a dealbreaker.
> >>>
> >>> However, part of writing code is commenting the code for reminders of
> >>> why little bits are the way they are. The problem is that the scribble
> >>> HTML output has stripped all comments from the chunks. I have tried
> >>> digging down into scribble/lp but I must admit the guts are outside my
> >>> ability to understand. I'm guessing it is because the reader has
> >>> already stripped comments from the syntax by the time Racket gets to
> >>> the "chunk" syntax rule. The one bit that seems to indicate it strips
> >>> comments (code:comment) never seems to be used anywhere. I know that
> >>> there are code examples with comments in the Racket documentation. Is
> >>> there any way to keep code comments preserved in the scribbled view of
> >>> chunks?
> >>>
> >>> Thanks,
> >>> Deren
> >>> ____________________
> >>>  Racket Users list:
> >>>  http://lists.racket-lang.org/users
> >>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120423/19f8b9b2/attachment-0001.html>

Posted on the users mailing list.