{"size": 1496, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/syntax/scribblings/free-vars.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/syntax/scribblings/free-vars.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/syntax/scribblings/free-vars.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 35.619047619, "max_line_length": 79, "alphanum_fraction": 0.6851604278}
#lang scribble/doc
@(require "common.rkt" (for-label syntax/free-vars) scribble/example)

@title[#:tag "free-vars"]{Computing the Free Variables of an Expression}

@defmodule[syntax/free-vars]

@defproc[(free-vars [expr-stx syntax?]
                    [insp inspector? _mod-decl-insp]
                    [#:module-bound? module-bound? any/c #f])
         (listof identifier?)]{

Returns a list of free @racket[lambda]- and @racket[let]-bound
identifiers in @racket[expr-stx] in the order in which each
identifier first appears within @racket[expr-stx]. The expression must be fully
expanded (see @secref[#:doc refman "fully-expanded"] and
@racket[expand]).

The inspector @racket[insp] is used to disarm @racket[expr-stx] and
sub-expressions before extracting identifiers. The default
@racket[insp] is the declaration-time inspector of the
@racketmodname[syntax/free-vars] module.}

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)))
]
