User Tools


Special Operator BLOCK

Syntax

  • block name form*result*

Arguments and Values

Description

block establishes a block named name and then evaluates forms as an implicit progn.

The special operators block and return-from work together to provide a structured, lexical, non-local exit facility. At any point lexically contained within forms, return-from can be used with the given name to return control and values from the block form, except when an intervening block with the same name has been established, in which case the outer block is shadowed by the inner one.

The block named name has lexical scope and dynamic extent.

Once established, a block may only be exited once, whether by normal return or explicit return.

Examples

(block empty)

NIL

(block whocares (values 1 2) (values 3 4))

3 4

(let ((x 1)) (block stop (setf x 2) (return-from stop) (setf x 3)) x)

2

(block early (return-from early (values 1 2)) (values 3 4))

1 2

(block outer (block inner (return-from outer 1)) 2)

1

(block twin (block twin (return-from twin 1)) 2)

2

In the below example, we contrast block behavior with corresponding example of catch.

(block b (flet ((b1 () (return-from b 1))) (block b (b1) (print 'unreachable)) 2))

1

Affected By

None.

Exceptional Situations

None.

See Also

Notes

None.