{"size": 3029, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/syntax/scribblings/stx.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/stx.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/stx.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": 26.8053097345, "max_line_length": 86, "alphanum_fraction": 0.6391548366}
#lang scribble/doc
@(require "common.rkt"
          (for-label racket/include
                     syntax/stx))

@(require scribble/eval)
@(define stx-eval (make-base-eval))
@(stx-eval '(require syntax/stx))

@title[#:tag "stx"]{Deconstructing Syntax Objects}

@defmodule[syntax/stx]

@defproc[(stx-null? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is either the empty list or a
@tech[#:doc refman]{syntax object} representing the empty list (i.e.,
@racket[syntax-e] on the @tech[#:doc refman]{syntax object} returns
the empty list).

@examples[#:eval stx-eval
  (stx-null? null)
  (stx-null? #'())
  (stx-null? #'(a))
]}

@defproc[(stx-pair? [v any/c]) boolean?]{

Returns @racket[#t] if @racket[v] is either a pair or a syntax object
representing a pair (see @techlink[#:doc refman]{syntax pair}).

@examples[#:eval stx-eval
  (stx-pair? (cons #'a #'b))
  (stx-pair? #'(a . b))
  (stx-pair? #'())
  (stx-pair? #'a)
]}

@defproc[(stx-list? [v any/c]) boolean?]{ 

Returns @racket[#t] if @racket[v] is a list, or if it is a sequence of
pairs leading to a syntax object such that @racket[syntax->list] would
produce a list.

@examples[#:eval stx-eval
  (stx-list? #'(a b c d))
  (stx-list? #'((a b) (c d)))
  (stx-list? #'(a b (c d)))
  (stx-list? (list #'a #'b))
  (stx-list? #'a)
]}

@defproc[(stx->list [stx-list stx-list?]) (or/c list? #f)]{

Produces a list by flatting out a trailing syntax object using
@racket[syntax->list].

@examples[#:eval stx-eval
  (stx->list #'(a b c d))
  (stx->list #'((a b) (c d)))
  (stx->list #'(a b (c d)))
  (stx->list (list #'a #'b))
  (stx->list #'a)
]}

@defproc[(stx-car [v stx-pair?]) any]{

Takes the car of a @techlink[#:doc refman]{syntax pair}.

@examples[#:eval stx-eval
  (stx-car #'(a b))
  (stx-car (list #'a #'b))
]}

@defproc[(stx-cdr [v stx-pair?]) any]{

Takes the cdr of a @techlink[#:doc refman]{syntax pair}.

@examples[#:eval stx-eval
  (stx-cdr #'(a b))
  (stx-cdr (list #'a #'b))
]}

@defproc[(stx-map [proc procedure?]
                  [stxl stx-list?] ...)
         list?]{

Equivalent to @racket[(map proc (stx->list stxl) ...)].

@examples[#:eval stx-eval
  (stx-map (λ (id) (free-identifier=? id #'a)) #'(a b c d))
]}

@defproc[(module-or-top-identifier=? [a-id identifier?]
				     [b-id identifier?])
	 boolean?]{

Returns @racket[#t] if @racket[a-id] and @racket[b-id] are
@racket[free-identifier=?], or if @racket[a-id] and @racket[b-id] have
the same name (as extracted by @racket[syntax-e]) and @racket[a-id]
has no binding other than at the top level.

This procedure is useful in conjunction with @racket[syntax-case*] to
match procedure names that are normally bound by Racket. For
example, the @racket[include] macro uses this procedure to recognize
@racket[build-path]; using @racket[free-identifier=?]  would not work
well outside of @racket[module], since the top-level
@racket[build-path] is a distinct variable from the @racketmodname[racket/base] export
(though it's bound to the same procedure, initially).}

@close-eval[stx-eval]

