# billy's right

## stevan apter — 2006-07-02 16:00:48

    i've added 'stack' and 'unstack' primitives to F:

        [0@] stack

        [1@] unstack

        1 2 3 stack

      1 2 3 [1 2 3]

        [4 5 6 7]

      1 2 3 [1 2 3] [4 5 6 7]

        unstack

      4 5 6 7

    consistent with my goal of mapping all the K verbs onto symbols (and having

    enough left over to support the necessary stack operators and combinators),

    i took advantage of the fact the atomic case of @ is identical to the 1

    element vector case.

    here's the relevant discussion from the paper (http://www.nsl.com/k/f/f.htm):

    Valence and Charge

    The valence of a program is a pair of non-negative integers. The first element of the pair is the stack-valence. The stack-valence

    of a program is the number of elements it takes from the stack. The second element is the queue-valence. The queue-valence is the

    number of elements it takes from the queue.

    The quote operator ' is the only primitive having non-zero queue-valence: it expects to find one element on the queue, which it

    enlists and pushes onto the stack. Hence, quote has stack-valence 1.

    The + operator has stack-valence 2. It takes two elements from the stack and pushes the sum onto the stack.

    The charge of a program is also a pair of non-negative integers. The first element is the stack-charge, and the second is the

    queue-charge.

    + has stack-charge 1 (it pushes a single element onto the stack) and queue-charge 0. $ (dup) has stack-valence 1 and stack-charge 2.

    \ (swap) has stack-valence 2 and stack-charge 2.

    ! (unquote) has stack-valence 1 and infinite queue-charge: it takes a quotation off the stack and pushes as many elements onto the

    queue as there are in the quotation.

    ` (dip) has stack-valence 2 and infinite queue-charge: it takes two things off the stack: a quotation and an element X and pushes

    first X, and then the quotation onto the queue.

    @ has stack-valence 1. If the top element on the stack is 0 (stack), it packages up the stack as a quotation and appends it to the

    stack. Hence, stack has stack-charge 1. If the top element of the stack is non-zero (unstack), it replaces the entire stack with the

    elements of the quotation it finds beneath the 0. Hence, unstack has infinite stack-charge. In both cases, if the stack beneath the

    top element is empty, the result is the empty stack.

    If the stack has fewer elements than the stack-valence, an F stack error is signalled. If the queue has fewer elements than the

    queue-valence, an F queue error is signalled.