<div dir="ltr">Thanks! Regarding the interaction-eval example, is there any way of wrapping this up in a macro so it doesn't have to be repeated for each use of examples in the file? I know that it's possible to get the module name via the 'enclosing-module-name syntax property, but I've got no idea how to rewrite the examples calls in the desc-expr that <span style="white-space:pre-wrap">proc-doc/names passes to </span><span style="white-space:pre-wrap">defproc*. (Presumably this needs to be done at run-time rather than documentation-time since the syntax inside the desc-expr can't access anything that isn't part of racket/base until it has called interaction-eval.)</span><div>
<span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">Thanks again,</span></div><div><span style="white-space:pre-wrap">Uri</span></div><div><br><div class="gmail_quote">On 20 May 2012 14:42, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">At Fri, 18 May 2012 13:47:54 +0100, Uri Zarfaty wrote:<br>
> I've been trying to use scribble/srcdoc for in-source documentation, and<br>
> have a couple of hopefully straightforward questions.<br>
><br>
> 1) Is it possible to use scribble/eval examples in proc-doc/names? Trying<br>
> this naively results in an undefined identifier error, presumably since the<br>
> function binding was not introduced to the source file that defines it<br>
> using a require.<br>
<br>
</div>When you use `scribble/eval', the default sandboxed evaluator has only<br>
`racket/base' bindings. Use `interaction-eval' to require other<br>
modules --- even if it's the enclosing module.<br>
<br>
Matthias's code does that in `define-module-local-eval'. See "ex.rkt"<br>
below for a more primitive example.<br>
<div class="im"><br>
> 2) Is it possible to use include-previously-extracted without requiring an<br>
> additional file for provide-extracted (e.g. by having the provide-extracted<br>
> in either the source or documentation file)?<br>
<br>
</div>You can use a submodule for this, but only with the repair that I've<br>
just pushed to the `scribble' languages to recognize `module' and<br>
`module*' submodule forms and not treat them as a expressions (i.e.,<br>
treat the them same as `require's or `define's).<br>
<br>
See "ex.scrbl" below for an example.<br>
<br>
----------------------------------------<br>
ex.rkt:<br>
----------------------------------------<br>
#lang at-exp racket/base<br>
(require scribble/srcdoc<br>
racket/contract<br>
(for-doc racket/base<br>
scribble/manual<br>
scribble/eval<br>
(for-label racket/base)))<br>
<br>
(define (negate x) (- x))<br>
<br>
(provide<br>
(proc-doc/names negate<br>
(-> number? number?)<br>
(x)<br>
@{Negates @racket[x].<br>
<br>
@(let ([e (make-base-eval)])<br>
(interaction-eval #:eval e (require "ex.rkt"))<br>
@examples[<br>
#:eval e<br>
(negate 7)<br>
])}))<br>
<br>
----------------------------------------<br>
ex.scrbl:<br>
----------------------------------------<br>
#lang scribble/manual<br>
@(require scribble/extract)<br>
<br>
@(module extracted racket/base<br>
(require scribble/extract)<br>
(provide-extracted "ex.rkt"))<br>
<br>
@(include-previously-extracted (submod "." extracted) #rx"negate")<br>
<br>
</blockquote></div><br></div></div>