<div dir="ltr">Thanks! I'll have a play with that :-)<div><br></div><div>Uri<br><br><div class="gmail_quote">On 18 May 2012 22:46, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.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="HOEnZb"><div class="h5"><br>
On May 18, 2012, at 8:47 AM, Uri Zarfaty wrote:<br>
<br>
> Hi all,<br>
><br>
> I've been trying to use scribble/srcdoc for in-source documentation, and have a couple of hopefully straightforward questions.<br>
><br>
> 1) Is it possible to use scribble/eval examples in proc-doc/names? Trying this naively results in an undefined identifier error, presumably since the function binding was not introduced to the source file that defines it using a require.<br>
><br>
> 2) Is it possible to use include-previously-extracted without requiring an additional file for provide-extracted (e.g. by having the provide-extracted in either the source or documentation file)?<br>
><br>
> Answers that only work in 5.3 (e.g. using submodules) are fine. Thanks!<br>
<br>
</div></div>I created a provide-and-scribble macro parallel to Matthew's effort on srcdoc. I stopped (not because I saw his, but because I have too many things to do at once.)<br>
<br>
My goal is to provide documentation for the HtDP teachpacks that always shows at least one interaction with the documented function i.e. a use of @interaction.<br>
<br>
Here is the idea, sketched out:<br>
<br>
;; provide-and-scribble.rkt<br>
;; the macros<br>
#lang at-exp racket<br>
<br>
(require (for-syntax syntax/parse) scribble/manual scribble/eval racket/sandbox)<br>
<br>
(provide<br>
define-module-local-eval<br>
provide-and-scribble<br>
)<br>
<br>
;; ---------------------------------------------------------------------------------------------------<br>
<br>
(define-for-syntax add-sections #f)<br>
<br>
(define-syntax (provide-and-scribble stx)<br>
(syntax-parse stx #:literals (defproc)<br>
[(provide-and-scribble (title (defproc (name args ...) range desc ...) ...) ...)<br>
(define add-docs-and-provide<br>
;; **********************************************************************************<br>
;; this needs something like a @defmodule[localname] but perhaps<br>
;; this should be added when I require the doc submodule<br>
;; **********************************************************************************<br>
#`((module+ doc (#,add-sections title (list (defproc (name args ...) range desc ...) ...)))<br>
...<br>
(provide name ... ...)))<br>
(cond<br>
[add-sections add-docs-and-provide]<br>
[else<br>
(set! add-sections (syntax-local-introduce #'add-sections))<br>
#`(begin<br>
(module+ doc<br>
(provide docs)<br>
(define *sections '())<br>
(define (#,add-sections stitle scontent)<br>
(set! *sections (cons (list stitle scontent) *sections)))<br>
(define (docs)<br>
(reverse *sections)))<br>
#,@add-docs-and-provide)])]))<br>
<br>
<br>
;; (define-module-local-eval name-of-evaluator)<br>
;; a make-base-eval whose namespace is initialized with the module where the macro is used<br>
(define-syntax-rule<br>
(define-module-local-eval name)<br>
(begin<br>
(define-namespace-anchor ns)<br>
(define name<br>
(parameterize ([sandbox-namespace-specs (list (lambda () (namespace-anchor->namespace ns)))]<br>
[sandbox-error-output 'string]<br>
[sandbox-output 'string])<br>
(make-base-eval)))))<br>
<br>
---------------------------------------------------------------------------------------<br>
<br>
;; provide-and-define.rkt<br>
;; a sample library that uses provide-and-scribble with @interaction<br>
#lang at-exp racket<br>
<br>
(require "provide-and-scribble.rkt" scribble/manual scribble/eval)<br>
<br>
(define-module-local-eval my-eval)<br>
<br>
(define (f x) `(f ,x))<br>
(define (g x) `(g ,x))<br>
(define (h x) `(h ,x))<br>
<br>
(provide-and-scribble<br>
("Numbers"<br>
@defproc[(f [x number?]) number?]{hello world @interaction[#:eval my-eval (f 10)]}<br>
@defproc[(g [x number?]) number?]{hello world @interaction[#:eval my-eval (g 10)]}<br>
)<br>
("Strings"<br>
@defproc[(h [x number?]) number?]{hello world @interaction[#:eval my-eval (h "hello")]}<br>
))<br>
<br>
---------------------------------------------------------------------------------------<br>
<br>
;; provide-and-test.scrbl<br>
;; the scribble document that uses the docs<br>
#lang scribble/manual<br>
<br>
@(require (submod "provide-and-define.rkt" doc))<br>
<br>
@(let loop ([s (docs)])<br>
(cond<br>
[(null? s) '()]<br>
[else<br>
(define-values (section-title stuff) (apply values (car s)))<br>
(cons @section{@section-title}<br>
(cons @stuff (loop (cdr s))))]))</blockquote></div><br></div></div>