View Source Document

eval.robin

;'<<SPEC'

### `eval` ###

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

`eval` evaluates its first argument to obtain an environment, then
evaluates its second argument to obtain an S-expression; it then
evaluates that S-expression in the given environment.

    | (eval (env) (literal
    |   (prepend (literal a)
    |             (prepend (literal b) ()))))
    = (a b)

    | (eval () (literal
    |   (prepend (literal a)
    |             (prepend (literal b) ()))))
    ? abort (unbound-identifier prepend)

Something fairly complicated that uses `bind`...?

    | (bind bindings (prepend
    |                  (prepend (literal same) (prepend equal? ()))
    |                  (prepend
    |                    (prepend (literal x) (prepend #f ()))
    |                    ()))
    |   (eval bindings (literal (same x x))))
    = #t

If two bindings for the same identifier are supplied in the environment
alist passed to `eval`, the one closer to the front of the alist takes
precedence.

    | (bind bindings (prepend
    |                  (prepend (literal foo) (prepend (literal yes) ()))
    |                  (prepend
    |                     (prepend (literal foo) (prepend (literal no) ()))
    |                     ()))
    |   (eval bindings (literal foo)))
    = yes

`eval` will happily use whatever type of value you like as the
environment, however, subsequent evaluation will fail when it
tries to look up things in that environment.

    | (eval 103 (literal
    |   (prepend (literal a)
    |            (prepend (literal b) ()))))
    ? abort (unbound-identifier prepend)

Evaluation expects the contents of the list which makes up the
environment to be two-element lists.  Any list of some other
format will not work for looking things up.

    | (eval (prepend #f ()) (literal
    |   (prepend (literal a)
    |            (prepend (literal b) ()))))
    ? abort (unbound-identifier prepend)

Evaluation expects the head of each sublist in the list which makes up the
environment to be a symbol.  Any list of some other
format will not work for looking things up.

    | (eval (prepend (prepend 7 (prepend #f ())) ()) (literal
    |   (prepend (literal a)
    |            (prepend (literal b) ()))))
    ? abort (unbound-identifier prepend)

`eval` expects exactly two arguments.

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

    | (eval 4 5 6)
    ? abort (illegal-arguments (4 5 6))

'<<SPEC'

(require eval)