git @ Cat's Eye Technologies Robin / master stdlib / and.robin
master

Tree @master (Download .tar.gz)

and.robin @masterraw · history · blame

;'<<SPEC'

<!--
Copyright (c) 2012-2024, Chris Pressey, Cat's Eye Technologies.
This file is distributed under a 2-clause BSD license.  See LICENSES/ dir.
SPDX-License-Identifier: LicenseRef-BSD-2-Clause-X-Robin
-->

### `and` ###

    -> Tests for functionality "Evaluate Robin Expression (with Boolean)"

`and` evaluates both of its arguments to booleans, and evaluates to the
logical conjunction (boolean "and") of these two values.

    | (and #t #t)
    = #t

    | (and #t #f)
    = #f

    | (and #f #t)
    = #f

    | (and #f #f)
    = #f

`and` expects exactly two arguments.

    | (and #f)
    ? abort

    | (and #t #f #f)
    ? abort (illegal-arguments

`and` expects both of its arguments to be booleans.

    | (and 100 #t)
    ? abort (expected-boolean 100)

    | (and #t 99)
    ? abort (expected-boolean 99)

`and` is short-circuiting in the sense that no arguments after the first
`#f` argument will be evaluated.  Fully testing this requires side-effects,
but it can be demonstrated as follows.

    | (and #f 100)
    = #f

'<<SPEC'

(define and (fun (a b)
  (if a (if b #t #f) #f)))