[racket] using scribble/eval in conjunction with scribble/lp
The `examples` form uses a fresh namespace for its evaluation. As part
of "lp.rkt", you could set up an evaluator that is initialized to use
the enclosing module's namespace.
========================================
;; lp.rkt:
#lang scribble/lp
@(require scribble/eval)
This would be a wonderful way to accomplish things!
@chunk[<*>
(define (f x)
<f-body>)]
@chunk[<f-body>
(* x x)]
And then, I could show an example:
@(define evaluator (make-base-eval))
@interaction-eval[#:eval evaluator
(begin
(dynamic-require "lp.rkt" #f)
(current-namespace
(module->namespace "lp.rkt")))]
@examples[
#:eval evaluator
(f 10)
]
========================================
To avoid having to write "lp.rkt" within "lp.rkt", you could construct
`evaluator` like this:
@(begin
(require syntax/location)
(define here (quote-source-file))
(define evaluator (make-base-eval))
(evaluator `(begin
(dynamic-require '(file ,here) #f)
(current-namespace
(module->namespace '(file ,here))))))
Meanwhile, I'll work on changing `scribble/lp` so that a module
implemented with `#lang scribble/lp` can be passed directly to
Scribble. That became possible when we added `doc` submodule support to
Scribble, but I never got around to adding the `doc` submodule in a
`scribble/lp` module's expansion.
At Sun, 14 Dec 2014 22:10:58 -0500, Benjamin Greenman wrote:
> No, that doesn't work for me either. Anyway, I was hoping I could export f
> and then run the examples in a second file (because we have to lp-include
> the literate program anyway):
>
> ;; lp.scrbl
> #lang scribble/manual
>
> @require[scribble/lp-include]
> @require[scribble/eval]
> @lp-include["example.rkt"]
> @examples[(f 10)]
>
>
> On Sun, Dec 14, 2014 at 4:59 PM, Joel McCracken <mccracken.joel at gmail.com>
> wrote:
> >
> > I have tried a few different things. In you case, I think adding a:
> >
> > @chunk[ <foo> (provide f)]
> >
> > ... will make lp-test work.
> >
> > I'm still can't get lp.rkt to become self-referential, though.
> >
> >
> >
> > On Sun, Dec 14, 2014 at 4:46 PM, Benjamin Greenman <blg59 at cornell.edu>
> > wrote:
> > > I tried and failed to figure this out. In particular, when I create the
> > > example "lp.rkt" file described at the top of the scribble/lp docs and
> > > require it "in the normal manner", the identifier f is unbound for me.
> > >
> > > The code I'm using is pasted below:
> > >
> > > ;; lp.rkt
> > > #lang scribble/lp
> > >
> > > Literate programs have chunks of code, like this one:
> > >
> > > @chunk[<f>
> > > (define (f x)
> > > <fs-body>)]
> > >
> > > and this one:
> > >
> > > @chunk[<fs-body>
> > > (* x x)]
> > >
> > > that, when assembled, produce a complete program, in this case:
> > >
> > > @racketblock[(define (f x)
> > > (* x x))]
> > >
> > > -----
> > >
> > > ;; lp-test.rkt
> > > #lang racket
> > > (require "lp.rkt")
> > > (f 3) ;; Error!
> > >
> > >
> > >
> > > On Sun, Dec 14, 2014 at 2:24 AM, Joel McCracken <
> > mccracken.joel at gmail.com>
> > > wrote:
> > >>
> > >> I'm trying to create a document that includes code, describes that
> > >> code, includes example usage, and exports some of the bindings so that
> > >> it may be included later.
> > >>
> > >> I've been looking at the scribble documentation, and it seems like all
> > >> this should be possible. I can't seem to figure out how to actually
> > >> run examples. Here's what I have:
> > >>
> > >> #lang scribble/lp
> > >>
> > >> @(require scribble/eval)
> > >>
> > >> This would be a wonderful way to accomplish things!
> > >>
> > >> @chunk[*
> > >> (define (f x)
> > >> <f-body>)]
> > >>
> > >> @chunk[<f-body>
> > >> (* x x)]
> > >>
> > >>
> > >> And then, I could show an example:
> > >>
> > >> @examples[
> > >> (f 10)
> > >> ]
> > >>
> > >>
> > >> Any advice would be really appreciated.
> > >> ____________________
> > >> Racket Users list:
> > >> http://lists.racket-lang.org/users
> >
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users