Add example to the free-vars docs.
Thanks to Christophe Scholliers.
This commit is contained in:
parent
45acc19f44
commit
caebbc65b6
|
@ -1,5 +1,5 @@
|
|||
#lang scribble/doc
|
||||
@(require "common.rkt" (for-label syntax/free-vars))
|
||||
@(require "common.rkt" (for-label syntax/free-vars) scribble/example)
|
||||
|
||||
@title[#:tag "free-vars"]{Computing the Free Variables of an Expression}
|
||||
|
||||
|
@ -23,3 +23,19 @@ sub-expressions before extracting identifiers. The default
|
|||
|
||||
If @racket[module-bound?] is non-false, the list of free variables also
|
||||
includes free module-bound identifiers.
|
||||
|
||||
@examples[
|
||||
(require (for-syntax racket/base syntax/parse syntax/free-vars))
|
||||
(define-syntax (print-body-free-vars stx)
|
||||
(syntax-parse stx
|
||||
#:literals (lambda)
|
||||
[(_ (~and lam (lambda (a ...) b ...)))
|
||||
(define expanded-body (local-expand #'lam 'expression '()))
|
||||
(syntax-parse expanded-body
|
||||
#:literals (#%plain-lambda)
|
||||
[(#%plain-lambda (arg ...) body)
|
||||
(displayln (free-vars #'body))
|
||||
expanded-body])]))
|
||||
|
||||
(lambda (x) (print-body-free-vars (lambda (y) x)))
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user