Common Lisp blocks provide a non-local exit mechanism very
throw, with lexical scoping.
This package actually implements
in terms of
catch; however, the lexical scoping allows the
byte-compiler to omit the costly
catch step if the
body of the block does not actually
cl-return-from the block.
The forms are evaluated as if by a
progn. However, if any of the forms execute
), they will jump out and return directly from the
cl-blockreturns the result of the last form unless a
cl-return-frommechanism is quite similar to the
throwmechanism. The main differences are that block names are unevaluated symbols, rather than forms (such as quoted symbols) that evaluate to a tag at run-time; and also that blocks are always lexically scoped. In a dynamically scoped
catch, functions called from the
catchbody can also
catch. This is not an option for
cl-block, where the
cl-return-fromreferring to a block name must appear physically within the forms that make up the body of the block. They may not appear within other called functions, although they may appear within macro expansions or
lambdas in the body. Block names and
catchnames form independent name-spaces.
In true Common Lisp,
defmacrosurround the function or expander bodies with implicit blocks with the same name as the function or macro. This does not occur in Emacs Lisp, but this package provides
cl-defmacroforms, which do create the implicit block.
The Common Lisp looping constructs defined by this package, such as
cl-dolist, also create implicit blocks just as in Common Lisp.
Because they are implemented in terms of Emacs Lisp's
throw, blocks have the same overhead as actual
catchconstructs (roughly two function calls). However, the byte compiler will optimize away the
catchif the block does not in fact contain any
cl-return-fromcalls that jump to it. This means that
cl-defunfunctions that don't use
cl-returndon't pay the overhead to support it.
This macro returns from the block named name, which must be an (unevaluated) symbol. If a result form is specified, it is evaluated to produce the result returned from the
This macro is exactly like
). Common Lisp loops like
cl-dolistimplicitly enclose themselves in
This macro executes statements while allowing for control transfer to user-defined labels. Each element of labels-or-statements can be either a label (an integer or a symbol), or a cons-cell (a statement). This distinction is made before macroexpansion. Statements are executed in sequence, discarding any return value. Any statement can transfer control at any time to the statements that follow one of the labels with the special form
). Labels have lexical scope and dynamic extent.