License: Public Domain , Load it with Quicklisp: (ql:quickload "first-time-value")
Library type: Macro , Project complexity: Trivial

first-time-value returns the result of evaluating a form in the current lexical and dynamic context the first time it's encountered, and the cached result of that computation on subsequent evaluations.

first-time-value » Dictionary

...2 » first-time-value

Package first-time-value

Description

Simply import first-time-value (and possibly also first-time-values) for normal usage. Don't (:use)!

This package will be mostly designed for explicit qualification of symbols if it ever exports more symbols, such as first-time-value:foo.

Macro first-time-value

form => object

Arguments and Values

  • form -- A form. Evaluated as described below.
  • object -- An object. The primary value returned by form the first time it evaluates successfully (without performing a non-local exit).

Description

On first evaluation, first-time-value attempts to evaluate form in the current lexical and dynamic context and cache the primary value it returns, and return that value.

If form performed a non-local exit, then the next evaluation of this first-time-value call will perform the aforementioned steps again.

On subsequent evaluations after a successful evaluation of form, first-time-value ignores form and returns the value that was previously cached.

first-time-value is similar to load-time-value, but evaluates its form in the current lexical and dynamic environment instead of in a null environment, and at the time that code at that location would normally be executed instead of at load time.

...2 » first-time-values

Macro first-time-values

form => object*

Arguments and Values

  • form -- A form.
  • objects -- All values returned by form the first time it evaluates successfully (without performing a non-local exit).

Description

Like first-time-value, except that all values returned from form are cached and returned instead of only the primary value.

(first-time-values form) == (values-list (first-time-value (multiple-value-list form)))