scribble-enhanced/graph/lib/doc/template.lp2.rkt
Georges Dupéron 494537057f Initial commit.
2015-10-21 18:35:42 +02:00

70 lines
1.9 KiB
Racket

#lang scribble/lp2
@(require "../../lib/doc.rkt")
@doc-lib-setup
@title[#:style manual-doc-style]{Life, the Universe and Everything.}
@(table-of-contents)
@section{Introduction}
@chunk[<foo>
(define foo 42)]
Here is a macro:
@CHUNK[<scribble-macro-expansion>
(define-for-syntax mymacro-tmp
(syntax-rules () [(_ a b) (let ((b 1)) a)]))
(define-syntax (mymacro-stx stx) #`'#,(mymacro-tmp stx))
(provide mymacro-stx)
(define-syntax mymacro mymacro-tmp)]
We can use it like this:
@chunk[<scribble-macro-expansion-example>
(mymacro (+ x 3) x)]
Which expands to (requires a bit of set-up boilerplate to have the output in
scribble, see
@url{http://lists.racket-lang.org/users/archive/2014-December/065175.html}):
@(begin
(require syntax/location scribble/eval)
(define here (quote-source-file))
(define evaluator (make-base-eval #:lang 'typed/racket))
(evaluator `(begin
(require (for-syntax racket/base))
(dynamic-require '(file ,here) #f)
(current-namespace
(module->namespace '(file ,here))))))
@interaction[#:eval evaluator
(mymacro-stx (+ x 3) x)]
@chunk[<test-foo>
(check-equal? foo 42)]
@section{Conclusion}
@chunk[<*>
(begin
(module main typed/racket
(require (for-syntax syntax/parse
racket/syntax
"../../lib/low-untyped.rkt")
"../../lib/low-untyped.rkt")
(provide foo)
<foo>
<scribble-macro-expansion>)
(require 'main)
(provide (all-from-out 'main))
(module* test typed/racket
(require (submod "..")
typed/rackunit)
<test-foo>
(require (submod ".." doc))))]