def mul((stack, dictionary)): ''' Replace the top two items on the stack with the result of multiplying them together. ''' a, b, stack = pop(stack, 2) return (a * b, stack), dictionary
def swap((stack, dictionary)): ''' Reverse the order of the top two items on the stack. ''' TOS, second, stack = pop(stack, 2) stack = push(stack, TOS, second) return stack, dictionary
def sub((stack, dictionary)): ''' Replace the top two items on the stack with the result of subtracting the top item from the second item. ''' a, b, stack = pop(stack, 2) return (b - a, stack), dictionary
def tuck((stack, dictionary)): ''' Put a "duplicate" of the item on the top of the stack just under the second item on the stack. (I.e. top, second, top.) ''' TOS, second, stack = pop(stack, 2) stack = push(stack, TOS, second, TOS) return stack, dictionary
def inscribe((stack, dictionary)): ''' Given a name string on the top of the stack and a "combo" command underneath it (see NewSeqWord, NewLoopWord, and NewBranchWord for how to make combo commands) "inscribe" the combo command into the dictionary under that name, replacing any previous command of that name. ''' name, word, stack = pop(stack, 2) dictionary = insert(dictionary, name, word) return stack, dictionary
def NewBranchWord((stack, dictionary)): ''' Create a new Branch command word. A branch consumes the top item on the stack and does one of two things depending on its "truth" value. Unlike Loops and Sequences which use all the items on the stack, Branch commands only take the top two items. The item on the top of the stack should be a function to use in case of "true" and the second should be a function to use for "false". ''' true, false, stack = pop(stack, 2) branch = (handle_branch, true, false) stack = push(stack, branch) return stack, dictionary
def add((stack, dictionary)): ''' Add the top two items on the stack and replace them with the sum. ''' a, b, stack = pop(stack, 2) return (a + b, stack), dictionary