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

Tree @master (Download .tar.gz)

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

### `sandbox` ###

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

`sandbox` takes a list of identifiers as its first argument, and evaluates
its second argument in an environment where all bindings *except* those
for the listed identifiers have been unbound.

    | (sandbox (prepend tail)
    |   (tail (prepend 8 (prepend 9 ()))))
    = (9)

    | (sandbox (prepend tail)
    |   (head (prepend 8 (prepend 9 ()))))
    ? abort (unbound-identifier head)

'<<SPEC'

(define sandbox
  (fexpr (args env)
    (eval (filter (fun (binding) (elem? (head binding) (head args))) env)
          (head (tail args)))))