# generalized stack operators

## stevan apter — 2000-06-27 11:30:54

    in conk, i've defined

    dup == 1 ndup;

    pop == 1 npop;

    dip == 1 ndip;

    ary == 1 nary;

    app == 1 napp;

    choice == 2 nchoice;

    swap == 1 2 nmswap;

    where the parameterized versions are primitive:

    ndip        [P] N -> R

    R is P applied to Nth item down.

    nary        [P] N -> R

    executes P, but no matter how many parameters this consumes, N are removed from the stack.

    napp        .. XN [P] N -> R1 ..

    executes P N times, with .. XN on top of the stack.  Returns N values R1 .. .

    npop        N -> R

    removes N items from the top of the stack.

    ndup        X N -> R

    makes N copies of the top of the stack.

    nmrot        N M -> R

    M-rotate the top N items of the stack.

    nmswap       N M -> R

    swap N-th and M-th items down on the stack.

    nlist        N -> X

    X is a list of the top N items.

    nchoice      I .. XN N -> Xi

    Xi is the I-th item of the top N items on the stack.

    particularly in the case of ary and app, this seemed more economical than having primitives

    app1, app2, app3, nullary, binary, ternary, etc.

    partly, it was a matter of trying to confine this family of operations to a small set.

    any ideas on the best way to proceed here?