cyclone/docs/api/srfi/2.md
2016-10-04 00:20:07 -04:00

1.2 KiB

SRFI 2 - and-let*

The (srfi 2) library provides the and-let* macro, an and with local bindings.

Like an ordinary and, an and-let* special form evaluates its arguments -- expressions -- one after another in order, till the first one that yields #f. Unlike and, however, a non-#f result of one expression can be bound to a fresh variable and used in the subsequent expressions. and-let* is a cross-breed between let* and and.

See the SRFI document for more information.

and-let*

(and-let* (claws) body

claws ::= '() | (cons claw claws)
claw  ::=  (variable expression) | (expression) |
           bound-variable
  • The claws are evaluated in the strict left-to-right order
  • For each claw, the expression part is evaluated first (or bound-variable is looked up)
  • If the result is #f, and-let* immediately returns #f
  • Otherwise, if the claw is of the form (variable expression) the expression's value is bound to a freshly made variable
  • The variable is available for the rest of the claws , and the body
  • As usual, all variables must be unique (like in let*)