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

Tree @0.7 (Download .tar.gz)

export.robin @0.7raw · history · blame

;'<<SPEC'

    -> 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
  (macro (self args env)
    (filter (fun (binding) (elem? (head binding) args)) env)))