Common Lisp Package: IT.UNIMIB.DISCO.LAZY

The Common Lisp Extensions Lazy Evaluation Package.

README:

FUNCTION

Public

DIVERGE

A function that never returns. It is equivalent to (LOOP). It should not be called striclty: called striclty: it will never terminate.

FORCE (THUNK)

Forces the evaluation of a THUNK. If THUNK is a regular value it is returned as is.

LAZY-LAMBDA-ARGLIST (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

LAZY-LAMBDA-CODE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

REPEATEDLY (FN &REST ARGS)

Returns a lazy list containing repeated applications of FN to ARGS.

TAIL (S)

Retirns the rest of a LIST or LAZY-STREAM.

THUNK-CODE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

Undocumented

COPY-LAZY-STREAM (INSTANCE)

LAZY-CONS-P (OBJECT)

LAZY-LAMBDA-P (OBJECT)

LAZY-STREAM-P (OBJECT)

THUNK-P (OBJECT)

Private

GET-LAZY-VERSION (F &OPTIONAL ERRORP)

Retrieves the lazy version of a function named F. If the lazy version does not exist and ERRORP is non-NIL an error of type UNDEFINED-LAZY-FUNCTION is signalled.

LAZY-CONS-HEAD (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

LAZY-CONS-TAIL (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

LAZY-FUNCTION-NAME-P (S)

Checks if the symbol S names a lazy function.

LAZY-NAME (S)

Creates a symbol suitable for naming a lazy function.

LAZY-STREAM-HEAD (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

LAZY-STREAM-TAIL (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

MAKE-THUNK-SETUP-CODE (ARG &OPTIONAL THUNKS-ENV)

Creates the actual code that sets up a thunk. The thunk is actually a closure wrapping around two variables maintaining the thunk memoization state.

PARSE-ORDINARY-LAMBDA-LIST (LAMBDA-LIST)

Parses a lambda list and returns each group of arguments as a separate value.

RENAME-LAMBDA-VARS (ARGLIST)

Traverses a (ordinary) lambda-list, making each argument ready for lazy evaluation. The function returns a (ordinary) lambda list with each argument appropriately renamed and ready to be thunked. It also returns a list of argument names and an a-list of argument name versus renamed argument. Default parameters are treated correctly and thunked in the process; keyword arguments are treated similarly, both in regular and in `extra keyword' form. &rest arguments are left untouched.

THUNK-FORM (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

THUNK-TYPE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

Undocumented

%CONS-LAZY-CONS (HEAD &OPTIONAL (TAIL (MAKE-THUNK NIL)))

%CONS-LAZY-STREAM (HEAD &OPTIONAL (TAIL (MAKE-THUNK NIL)))

%MAKE-THUNK% (FORM CODE)

ARGLIST (FUNCTION-DESIGNATOR)

COPY-LAZY-CONS (INSTANCE)

CREATE-THUNK-CALL-EXPANSION (ARG-NAME ARG-THUNK-NAME)

CREATE-VAR-THUNK-CALL-EXPANSION (VAR-NAME-THUNK)

SETFGET-LAZY-VERSION (LF NAME)

LAMBDA-EXPRESSION-P (F)

MAKE-LAZY-LAMBDA (&OPTIONAL (CODE (LAMBDA (&REST ARGS) (DECLARE (IGNORE ARGS)) (ERROR 'UNDEFINED-LAZY-LAMBDA))) (ARGLIST '(&REST ARGS)))

MACRO

Public

CALL (F &REST ARGS)

The LAZY:CALL macro generalizes FUNCALL in order to handle lazy functions. The LAZY:CALL macro introduces lazy evaluation in Common Lisp. The LAZY:CALL form ensures that, if possible, a lazy version of the function F is called, in which case all the arguments are automatically `thunked'. If no lazy version of F can be retrieved then F is FUNCALLed in the normal, strict, way with no `thunking' of the arguments.

CONS-STREAM (HEAD TAIL)

Constructs a LAZY-STREAM, DELAYing the TAIL argument.

DEF-LAZY-FUNCTION (NAME ARGS &BODY BODY)

Defines a lazy function. The function assumes that each argument is passed as a `thunk', which gets FORCEd as needed.

DEFLAZY (NAME ARGS &BODY BODY)

Defines a function while ensuring that a lazy version exists as well.

DELAY (EXPRESSION)

Delays an EXPRESSION by wrapping it in a `thunk' (i.e. a closure).

LAZILY (&BODY BODY)

Ensures that lazy functions are called lazily with LAZY:CALL. The macro code-walks BODY and whenever it finds an application that has a lazily defined operator, then it rewrites such application with LAZY:CALL.

LAZY (FUNCTION-SPEC &OPTIONAL (ERRORP T))

Transforms a function into a lazy equivalent. The LAZY macro is akin to the FUNCTION special operator. The function specified in FUNCTION-SPEC can be a symbol, a lambda expression or a FUNCTION special form. The macro operates at the syntactic level. The result is a function which may evaluate its arguments in a lazy way. This is achieved by ensuring that each argument is automatically interpreted as a 'thunk'. If FUNCTION-SPEC is a symbol which names a lazy function (cfr. LAZY-FUNCTION-NAME-P) then this is the result; if FUNCTION-SPEC is a lambda expression then it is `lazyfied'. The same happens if FUNCTION-SPEC is of the form (FUNCTION (LAMBDA ...)). If FUNCTION-SPEC is of the form (FUNCTION <symbol>), then LAZY falls back to the first case. In every other case, LAZY may yield a `regular' function. If ERRORP is non-NIL, an error of type INVALID-LAZY-ARGUMENT is generated if there is no way to associate FUNCTION-SPEC to a function; otherwise NIL is returned.

LET/LAZY (BINDINGS &BODY BODY)

The macro operates like LET, but is delays the evaluation of the bindings.

MAKE-THUNK (EXPR)

Expands into code that creates a thunk wrapping around EXPR.

Undocumented

SLACKING (&BODY BODY)

Private

TAU-LAMBDA (ARGLIST &BODY BODY)

Creates a LAZY-LAMBDA. This macro is the syntactic equivalent of the LAMBDA macro for LAZY-LAMBDAs. The name comes from the Greek 'tempelis', which means 'lazy'; hence the 'tau' prefix.

GENERIC-FUNCTION

Private

Undocumented

UNDEFINED-LAZY-FUNCTION-NAME (CONDITION)

VARIABLE

Private

*BREAK-IF-NON-LAZY-CALL-P*

If non-NIL the LAZY:CALL macro breaks when it resolves in a strict call.

*WARN-IF-NON-LAZY-CALL-P*

If non-NIL the LAZY:CALL macro generates a warning when it resolves in a strict call.

CLASS

Public

LAZY-CONS

The Lazy Cons Structure. The LAZY-CONS structure has both head and tail lazy. It includes LAZY-STREAM.

LAZY-LAMBDA

The Lazy Lambda Structure. This structure is a wrapper around a LAMBDA representing the actual lazy code. Its main use is as a `type' used in discrimination. The slot CODE contains the actual lazy code, while the slot ARGLIST containes the LAMBDA argilist. The slots are read only. No `copier' is defined. The instances are `immutable'. The constuctor is defined as MAKE-LAZY-LAMBDA (&optional CODE ARGLIST) with appropriate defaults. The other usual functions automatically generated by DEFSTRUCT work as expected.

LAZY-STREAM

The Lazy Stream Structure. The traditional implementation of SICP-like streams. The LAZY-STREAM structure has a strict head and a lazy tail.

THUNK

The Thunk Structure. A wrapper for code fragments that will be evaluated after a delay. Thunks can be created either directly by the macro MAKE-THUNK or by the macro DELAY.

CONDITION

Public

INVALID-LAZY-ARGUMENT

The Invalid Lazy Argument Condition. This condition is signalled by LAZY operator when it cannot get hold of a lazy version of the argument.

UNDEFINED-LAZY-FUNCTION

The Undefined Lazy Function Condition. A simple subclass of the UNDEFINED-FUNCTION condition. This is signalled by the LAZY operator and the LAZY:CALL macro when trying to access an undefined lazy function. This may happen also when a function has a strict definition but no lazy counterpart.

Private

Undocumented

UNDEFINED-LAZY-LAMBDA