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

Tree @master (Download .tar.gz)

unbind.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
-->

### `unbind` ###

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

`unbind` removes the given identifier from the environment and evaluates its
second argument in that reduced environment.

    | (unbind if (if #t (literal x) (literal y)))
    ? abort (unbound-identifier if)

If the identifier doesn't exist in the environment, no change is made to
the environment.

    | (unbind yog-sothoth (if #t (literal x) (literal y)))
    = x

`unbind` removes all trace of binding from the given identifier; if that
identifier has several definitions that are shadowed, none of them will be
in effect.

    | (let ((x 7))
    |   (let ((x 8))
    |     (unbind x
    |       x)))
    ? abort (unbound-identifier x)

'<<SPEC'

(define unbind
  (fexpr (args env)
    (eval (filter (fun (binding) (if (equal? (head binding) (head args)) #f #t)) env)
          (head (tail args)))))