git @ Cat's Eye Technologies Robin / master stdlib / bound-p.robin
master

Tree @master (Download .tar.gz)

bound-p.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
-->

### `bound?` ###

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

`bound?` takes a single argument, which should be a symbol, and
evaluates to `#t` if it the symbol is bound to a value in the
current environment, or `#f` if it is not.

    | (bound? bound?)
    = #t

    | (bound? xuzumsunazun)
    = #f

    | (bind xuzumsunazun 3 (bound? xuzumsunazun))
    = #t

The single argument to `bound?` should be a symbol.

    | (bound? 3)
    ? abort (expected-symbol 3)

`bound?` expects exactly two arguments.

    | (bound? bound? bound?)
    ? abort (illegal-arguments (bound? bound?))

    | (bound?)
    ? abort (illegal-arguments ())

'<<SPEC'

(define bound? (fexpr (args env)
  (if (equal? args ())
    (abort (list (literal illegal-arguments) args))
    (if (equal? (tail args) ())
      (bind symbol (head args)
        (if (symbol? symbol)
          (if (equal? (lookup symbol env) ()) #f #t)
          (abort (list (literal expected-symbol) symbol))))
      (abort (list (literal illegal-arguments) args))))))