17 mzlib/etc

▼ |  | Mz Lib: Legacy Libraries

1 | mzlib/ a-signature
2 | mzlib/ a-unit
3 | mzlib/ async-channel
4 | mzlib/ awk
5 | mzlib/ class
6 | mzlib/ cm
7 | mzlib/ cm-accomplice
8 | mzlib/ cmdline
9 | mzlib/ cml
10 | mzlib/ compat
11 | mzlib/ compile
12 | mzlib/ contract
13 | mzlib/ control
14 | mzlib/ date
15 | mzlib/ deflate
16 | mzlib/ defmacro
17 | mzlib/ etc
18 | mzlib/ file
19 | mzlib/ for
20 | mzlib/ foreign
21 | mzlib/ include
22 | mzlib/ inflate
23 | mzlib/ integer-set
24 | mzlib/ kw
25 | mzlib/ list
26 | mzlib/ match
27 | mzlib/ math
28 | mzlib/ md5
29 | mzlib/ os
30 | mzlib/ pconvert
31 | mzlib/ pconvert-prop
32 | mzlib/ plt-match
33 | mzlib/ port
34 | mzlib/ pregexp
35 | mzlib/ pretty
36 | mzlib/ process
37 | mzlib/ restart
38 | mzlib/ runtime-path
39 | mzlib/ sandbox
40 | mzlib/ sendevent
41 | mzlib/ serialize
42 | mzlib/ shared
43 | mzlib/ string
44 | mzlib/ struct
45 | mzlib/ stxparam
46 | mzlib/ surrogate
47 | mzlib/ tar
48 | mzlib/ thread
49 | mzlib/ trace
50 | mzlib/ traceld
51 | mzlib/ trait
52 | mzlib/ transcr
53 | mzlib/ unit
54 | mzlib/ unit-exptime
55 | mzlib/ unit200
56 | mzlib/ unitsig200
57 | mzlib/ zip
| Bibliography
| Index

On this page:

begin-lifted
begin-with-definitions
define-syntax-set
evcase
identity
let+
loop-until
namespace-defined?
nand
nor
opt-lambda
recur
rec
this-expression-source-directory
this-expression-file-name
hash-table

Racket
top contents ← prev up next →

(require mzlib/etc) | package: compatibility-lib

The mzlib/etc library re-exports the following from scheme/base and other libraries:

> boolean=?
> true
> false
> build-list
> build-string
> build-vector
> compose
> local
> symbol=?
> nand
> nor

> syntax (begin-lifted expr ...+)

Lifts the exprs so that they are evaluated once at the “top level” of the current context, and the result of the last expr is used for every evaluation of the begin-lifted form.

When this form is used as a run-time expression within a module, the “top level” corresponds to the module’s top level, so that each expr is evaluated once for each invocation of the module. When it is used as a run-time expression outside of a module, the “top level” corresponds to the true top level. When this form is used in a define-syntax, letrec-syntax, etc. binding, the “top level” corresponds to the beginning of the binding’s right-hand side. Other forms may redefine “top level” (using local-expand/capture-lifts) for the expressions that they enclose.

> syntax (begin-with-definitions defn-or-expr ...)

The same as (block defn-or-expr ...).

> syntax (define-syntax-set (id ...) defn ...)

Similar to define-syntaxes, but instead of a single body expression, a sequence of definitions follows the sequence of defined identifiers. For each identifier, the defns should include a definition for id/proc. The value for id/proc is used as the (expansion-time) value for id.

The define-syntax-set form is useful for defining a set of syntax transformers that share helper functions, though begin-for-syntax now serves essentially the same purposes.

Examples:

> (define-syntax-set (let-current-continuation
> let-current-escape-continuation)
> (define (mk call-id)
> (lambda (stx)
> (syntax-case stx ()
> [(_ id body1 body ...)
> (with-syntax ([call call-id])
> #'(call (lambda (id) body1 body ...)))])))
> (define let-current-continuation/proc
> (mk (quote-syntax call/cc)))
> (define let-current-escape-continuation/proc
> (mk (quote-syntax call/ec))))

> syntax (evcase key-expr (value-expr body-expr ...) ...+)
> (evcase key-expr (value-expr body-expr ...) ... [else body-expr ...])

The evcase form is similar to case, except that expressions are provided in each clause instead of a sequence of data. After key-expr is evaluated, each value-expr is evaluated until a value is found that is eqv? to the key value; when a matching value is found, the corresponding body-exprs are evaluated and the value(s) for the last is the result of the entire evcase expression.

The else literal is recognized either as unbound (like in the mzscheme language) or bound as else from scheme/base.

> procedure (identity v) → any/c
> v : any/c

Returns v.

> syntax (let+ clause body-expr ...+)
> clause |  | = |  | (val target expr)
> |  | | |  | (rec target expr)
> |  | | |  | (vals (target ...) expr)
> |  | | |  | (recs (target expr) ...)
> |  | | |  | (_ expr ...)
> target |  | = |  | id
> |  | | |  | (values id ...)

A binding construct that specifies scoping on a per-binding basis instead of a per-expression basis. It helps eliminate rightward-drift in programs. It looks similar to let, except each clause has an additional keyword tag before the binding variables.

Each clause has one of the following forms:

- (val target expr) : Binds target non-recursively to expr.

- (rec target expr) : Binds target recursively to expr.

- (vals (target expr) ...) : The targets are bound to the exprs. The environment of the exprs is the environment active before this clause.

- (recs (target expr) ...) : The targetss are bound to the exprs. The environment of the exprs includes all of the targetss.

- (_ expr ...) : Evaluates the exprs without binding any variables.

The clauses bind left-to-right. When a target is (values id ...), multiple values returned by the corresponding expression are bound to the multiple variables.

Examples:

> > (let+ ([val (values x y) (values 1 2)])
> (list x y))
> '(1 2)
> > (let ([x 1])
> (let+ ([val x 3]
> [val y x])
> y))
> 3

> procedure (loop-until start done? next f) → void?
> start : any/c
> done? : (any/c . -> . any)
> next : (any/c . -> . any/c)
> f : (any/c . -> . any)

Repeatedly invokes the f procedure until the done? procedure returns #t:

> (define (loop-until start done? next f)
> (let loop ([i start])
> (unless (done? i)
> (f i)
> (loop (next i)))))

> procedure (namespace-defined? sym) → boolean?
> sym : symbol?

Returns #t if namespace-variable-value would return a value for sym, #f otherwise.

> syntax (nand expr ...)

Same as (not (and expr ...)).

> syntax (nor expr ...)

Same as (not (or expr ...)).

> syntax (opt-lambda formals body ...+)

Supports optional (but not keyword) arguments like lambda from scheme/base.

> syntax (recur id bindings body ...+)

Equivalent to (let id bindings body ...+).

> syntax (rec id value-expr)
> (rec (id arg-id ...) expr)
> (rec (id arg-id ... . rest-id) expr)

Equivalent, respectively, to

> (letrec ([id value-expr]) id)
> (letrec ([id (lambda (arg-id ...) value-expr)]) id)
> (letrec ([id (lambda (arg-id ... . rest-id) value-expr)]) id)

> syntax (this-expression-source-directory)
> (this-expression-source-directory datum)

> > > See scheme/runtime-path for a definition form that works better when creating executables.

Expands to an expression that evaluates to the directory of the file containing the source datum. If datum is not supplied, then the entire (this-expression-source-directory) expression is used as datum.

If datum has a source module, then the expansion attempts to determine the module’s run-time location. This location is determined by preserving the lexical context of datum in a syntax object, extracting its source module path at run time, and then resolving the module path.

Otherwise, datum’s source file is determined through source location information associated with datum, if it is present. As a last resort, current-load-relative-directory is used if it is not #f, and current-directory is used if all else fails.

A directory path derived from source location is always stored in bytes in the expanded code, unless the file is within the result of find-collects-dir, in which case the expansion records the path relative to (find-collects-dir) and then reconstructs it using (find-collects-dir) at run time.

> syntax (this-expression-file-name)
> (this-expression-file-name datum)

Similar to this-expression-source-directory, except that only source information associated with datum or (this-expression-file-name) is used to extract a filename. If no filename is available, the result is #f.

> syntax (hash-table (quote flag) ... (key-expr val-expr) ...)

Creates a new hash-table providing the quoted flags (if any) to make-hash-table, and then mapping each key to the corresponding values.
top contents ← prev up next →