Andlet
1 Andlet
andlet
andlet*
7.8

Andlet

Deren Dohoda <deren.dohoda@gmail.com>

 (require andlet) package: andlet

1 Andlet

The provided forms allow one to combine the basic Racket and logic with let.

syntax

(andlet ([id val-expr #:test maybe-proc] ...) expr ...)

Like Racket’s let, except the result of each expression val-exp in the (id val-exp) pairs is checked to be not #f. Any time a val-expr evaluates to #f, the entire andlet expression is #f and subsequent bindings are not evaluated.

If a different condition than merely checking for falisty is required, use the optional argument #:test to give a procedure to use for generating the #t or #f value. Like Racket, anything which isn’t #f is considered #t.

Unlike Racket’s let, andlet is not capable of the named-let pattern of creating a procedure.

Example:
> (andlet ((a 10)
           (b 20 #:test number?)
           (c 'q #:test number?)
           (d (/ 1 0)))
    (displayln c) (+ a b))

#f

syntax

(andlet* ([id val-exp #:test maybe-proc] ...) expr ...)

Like andlet, except as with Racket’s let*, bindings are sequentially introduced so subsequent val-exps may refer to the bound ids of previous name/value pairs.

Example:
> (andlet* ((a 10)
            (b (+ a 10))
            (a 20))
    (+ a b))

40