Next: , Previous: , Up: expander utils   [Index]


15.4.2 Identifiers processing: generic functions

Function: identifier-bound? id

Return #t if the identifier id is lexically bound; otherwise return #f.

(identifier-bound? #'woppa-woppa-woppa)
⇒ #f

(let ((ciao 123))
  (define-syntax (doit stx)
    (identifier-bound? #'ciao))
  (doit))
⇒ #t

(let ((ciao 123))
  (define-syntax (doit stx)
    (syntax-case stx ()
      ((_ ?id)
       (identifier-bound? #'?id))))
  (doit ciao))
⇒ #t

(let ()
  (define ciao 123)
  (define-syntax (doit stx)
    (syntax-case stx ()
      ((_ ?id)
       (identifier-bound? #'?id))))
  (doit ciao))
⇒ #t

(let ()
  (let-syntax ((ciao (identifier-syntax 123)))
    (define-syntax (doit stx)
      (syntax-case stx ()
        ((_ ?id)
         (identifier-bound? #'?id))))
    (doit ciao)))
⇒ #t
Function: identifier->string id

Return a string representing the name of the identifier id.

Function: string->identifier ctx str

Build and return a new identifier, in the same lexical context of ctx, having the string str as name.

Function: identifier-prefix prefix id

Build and return a new identifier, in the same lexical context of the identifier id, whose string name is the concatenation of prefix and id. prefix can be a string, symbol or identifier.

(import (vicare))

(bound-identifier=? (identifier-prefix "this-" #'that)
                    #'this-that)
⇒ #t
Function: identifier-suffix id suffix

Build and return a new identifier, in the same lexical context of the identifier id, whose string name is the concatenation of id and suffix. suffix can be a string, symbol or identifier.

(bound-identifier=? (identifier-suffix #'this "-that")
                    #'this-that)
⇒ #t
Function: identifier-append ctx item

Build and return a new identifier, in the same lexical context of the identifier ctx, whose string name is the concatenation of the arguments item. Each item can be a string, symbol or identifier.

(bound-identifier=? (identifier-append #'this "-that" '-those)
                    #'this-that-those)
⇒ #t
Function: identifier-format ctx template item

Build and return a new identifier, in the same lexical context of the identifier ctx, whose string name is the result of formatting the string template with the arguments item. template can be a string including the same escape sequences of format from (vicare) (see format). Each item can be a string, symbol or identifier.

(bound-identifier=?
 (identifier-format #'here "~a-~a-~a" #'this "that" 'those)
 #'this-that-those)
⇒ #t
Function: duplicate-identifiers? ids
Function: duplicate-identifiers? ids identifier=

Search the list of identifiers ids for duplicate identifiers; at the first duplicate found, return it; return #f if no duplications are found.

The optional argument identifier= must be the predicate function used to compare identifiers; when not given it defaults to free-identifier=?.

Function: delete-duplicate-identifiers ids
Function: delete-duplicate-identifiers ids identifier=

Given the list of identifiers ids remove the duplicate identifiers and return a proper list of unique identifiers.

The optional argument identifier= must be the predicate function used to compare identifiers; when not given it defaults to free-identifier=?.

Function: identifier-memq id ids
Function: identifier-memq id ids identifier=

Search the list of identifiers ids for one that matches id and return the sublist starting with it; return #f if id is not present.

The optional argument identifier= must be the predicate function used to compare identifiers; when not given it defaults to free-identifier=?.

Syntax: with-implicits ((?ctx ?symbol ...) ...) . ?body

Wrapper for with-syntax which defines the identifiers ?symbol with the same context of ?ctx. ?ctx must be an expression evaluating to an identifier; it is evaluated only once. ?symbol must be Scheme symbols.

For example:

(syntax-case stx ()
  ((id)
   (identifier? #'id)
   (with-implicits ((#'id x y))
     #'(list x y))))

is equivalent to:

(syntax-case stx ()
  ((id)
   (identifier? #'id)
   (with-syntax ((x (datum->syntax #'id 'x))
                 (y (datum->syntax #'id 'y)))
     #'(list x y))))

NOTE This macro is derived from the one documented in the Chez Scheme User’s Guide.


Next: , Previous: , Up: expander utils   [Index]