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

Tree @master (Download .tar.gz)

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

### `export` ###

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

`export` treats its arguments as a list of identifiers, and returns an
environment where only those identifiers are bound to values.

The original idea for `sandbox` was that it could be used in the body of
a module to restrict the visible identifiers to those the module wished
to export, which could then actually be exported with `env`.  However,
this still required `env` to be a visible identifier (and thus exported.)
`export` simply evaluates to a binding alist which can be returned
directly.

Note: the order of the bindings in the binding alist isn't guaranteed;
thus these tests are written to search the resulting alist.

    | (let ((a 1) (b 6))
    |   (length (export a b)))
    = 2

    | (let ((a 1) (b 6))
    |   (lookup (literal a) (export a b)))
    = (1)

    | (let ((a 1) (b 6))
    |   (lookup (literal b) (export a b)))
    = (6)

    | (lookup (literal head) (export head tail))
    = (head)

    | (lookup (literal prepend) (export head tail))
    = ()

'<<SPEC'

(define export
  (fexpr (args env)
    (filter (fun (binding) (elem? (head binding) args)) env)))