scribble-code-examples
code-examples
make-code-eval
6.12

scribble-code-examples

 (require scribble-code-examples)
  package: scribble-code-examples

procedure

(code-examples #:lang language    
  #:context context    
  [#:inset? inset?    
  #:show-lang-line show-lang-line    
  #:eval evaluator]    
  examples ...)  block?
  language : string?
  context : syntax?
  inset? : boolean? = #true
  show-lang-line : (or/c boolean? pre-flow?) = #false
  evaluator : evaluator? = (make-code-eval #:lang language)
  examples : string?
A scribble examples form that works for non-s-expression languages.

For example, this:

@code-examples[#:lang "at-exp racket" #:context #'here]|{

(+ 1 2)

@+[1 3]

}|

Produces this:

>

 

(+ 1 2)

3

>

 

@+[1 3]

4

And this:

@code-examples[#:lang "at-exp racket" #:context #'here]|{

(require scribble-code-examples (for-label racket/base))

@code-examples[#:lang "at-exp racket" #:context #'here]|{

(+ 1 2)

@+[1 3]

}|

}|

Produces this:

>

 

(require scribble-code-examples (for-label racket/base))

>

 

@code-examples[#:lang "at-exp racket" #:context #'here]|{
(+ 1 2)
@+[1 3]
}|

(nested-flow (style 'code-inset '()) (list (table (style #f '()) (list (list (table (style #f (list (table-cells (list (list (style #f '(baseline)) (style #f '(baseline)) (style #f '(baseline))))))) (list (list (paragraph #0=(style #f '()) (element 'tt '(">"))) (paragraph #0# #3=(element 'hspace '(" "))) (table #9=(style "RktBlk" (list 'tt-chars #1=(list (css-addition '(collects #"scribble" #"racket.css")) (tex-addition '(collects #"scribble" #"racket.tex"))))) (list (list (paragraph #8=(style #f '(omitable)) (list "" (element #2=(style "RktMeta" (list 'tt-chars #1#)) "") (element #5=(style "RktPn" (list 'tt-chars #1#)) "(") (sized-element #7=(style "RktSym" (list 'tt-chars #1#)) #6=(cached-delayed-element #<procedure:...ibble/racket.rkt:165:20> #<procedure:...ibble/racket.rkt:186:20> #<procedure:...ibble/racket.rkt:187:20> ...) ...) (element #2# "") #3# (element #2# "") (element #4=(style "RktVal" (list 'tt-chars #1#)) "1") (element #2# "") #3# (element #2# "") (element #4# "2") (element #5# ")") (element #2# "")))))))))) (list (paragraph #0# (element #10=(style "RktRes" (list 'tt-chars #1#)) "3"))) (list (table (style #f (list (table-cells (list (list (style #f '(baseline)) (style #f '(baseline)) (style #f '(baseline))))))) (list (list (paragraph #0# (element 'tt '(">"))) (paragraph #0# #3#) (table #9# (list (list (paragraph #8# (list "" (element #2# "") (element #5# "@") (sized-element #7# #6# ...) (element #5# "[") (element #4# "1") (element #2# "") #3# (element #2# "") (element #4# "3") (element #5# "]") (element #2# "")))))))))) (list (paragraph #0# (element #10# "4")))))))

procedure

(make-code-eval #:lang language)  evaluator?

  language : string?
Creates a sandbox evaluator that can be used as the #:eval argument for code-examples.

Examples:

>

 

(require scribble-code-examples)

>

 

(define ev (make-code-eval #:lang "racket"))

>

 

(ev '(+ 1 2))

3

>

 

(ev "(+ 1 2)")

3