x-lang

← Index

x/core/alist

Association-list bootstrap: get/has?/del/put/keys and let-opts.

The bootstrap layer the object system runs on, plus the let-opts form.

The full association API is the Assoc class: (Assoc merge a b), (Assoc map f al), …

Lookup

%assoc-get

Look up a key in an alist, returning its value or nil.

Bootstrap layer: the object system dispatches through this. Class API: (Assoc get …).

Parameters:

Returns: ANY — Value associated with key, or nil if not found

%assoc-has?

Test whether a key exists in an alist.

Bootstrap layer: the object system dispatches through this. Class API: (Assoc has? …).

Parameters:

Returns: BOOL — True if key is present

%assq

Look up a key in an alist, returning the entry pair or nil.

Entry-returning eq? lookup. Class API: (Assoc entry …).

Parameters:

Returns: ANY — The (key . value) entry pair, or nil if not found

%assoc-str

Look up a string key in an alist, returning the entry pair or nil.

The str=? side of the key-equality split: tables keyed by converted (cross-base) names use this.

Parameters:

Returns: ANY — The (key . value) entry pair, or nil if not found

Modification

%assoc-del

Remove all entries for a key from an alist.

Bootstrap layer. Class API: (Assoc del …).

Parameters:

Returns: LIST — Alist without the given key

%assoc-put

Set a key-value pair, replacing any existing entry for that key.

Bootstrap layer: the object system dispatches through this. Class API: (Assoc put …).

Parameters:

Returns: LIST — Alist with the key set to val

Extraction

%assoc-keys

Return all keys from an alist.

Bootstrap layer: the object system’s introspection uses this. Class API: (Assoc keys …).

Parameters:

Returns: LIST — List of keys

Option stores

let-opts

Bind locals from an option store (alist or plist) with lazy per-binding defaults.

Each binding is name (name default) (name key default). Defaults are

lazy (run only when the option is absent) and may reference earlier bindings.

The source evaluates to an alist ((k . v) …) or a flat plist (k v …).

Examples:

(let-opts '(a 1) ((a 0) (b 0)) (+ a b)) => 1

See also: %assoc-get