# function quotation or voracious evaluation?

## stevan apter — 2000-06-26 04:40:13

    it is easy to implement the voracious evaluation strategy.

    E is the k function evaluates something y on stack x:

        E[2 3;`add]

     ,5

    let the something y be a list of things to evaluate, and

    we apply E over y with an initial state x:

        2 3 4 5 E/`add`sub

    -1 5

    which is equivalent to

        E[E[2 3 4 5;`add];`sub]

    the case we care about is when the result is incompletely

    evaluated:

        2 3 E/(,,`add),`first

    (`add;2;3)

    which is a snapshot of the internal state when

        k>2 3

        2 3

        k>[+] first

        2 3 +

    is entered.  we want the evaluater to repeatedly feed the

    resulting stack to itself until the result is the same

    twice in a row, so we define

        EE:{(()E/|:)/E[x;y]}

    and say:

        2 3 EE/(,`add),`first

    ,5

    (()E/|:) is the function of one argument x which reverses

    x, and then evaluates it against the empty stack ().  (the

    input needs to be reversed because the stack is represented

    as a list.)  in k, a monadic function f applied over an

    argument, f/a, repeatedly applies f to its own result

    (starting with a) until the result "converges" -- until it

    is the same twice in a row, or until it matches initial a.

    in other words, EE is a single step evaluator -- it takes

    exactly one item from the input stack -- and evaluates it

    against the current stack to produce the new stack.  but

    it does it voraciously, so that if the result is not

    completely evaluated, it has another go at it.