def rebalance((stack, dictionary)): ''' This "rebalances" a dictionary. It makes it more efficient to access commands in the dictionary if you've added a lot of new ones. It's a good idea to use this command before creating a pickle to save so that the saved pickle's dictionary is already balanced. ''' dictionary = fill_tree((), items(dictionary)) return stack, dictionary
def view1(I): '''Print the stack to stdout using the pprint module.''' pprint.pprint(I[0]) print def nullView(I): '''"Do nothing" view.''' pass # An initial interpreter to use for spawning worlds. It has an empty # stack and whatever commands are defined by default in the library # module. ROOT = (), fill_tree((), words) class World(object): ''' Manage an interpreter, a view function, and serialization to a file or file-like object. This object takes a view function (any callable that accepts an interpreter) and optionally an initial interpreter and a save file. It creates a Serializer object to save commands and results, and it provides a step() method that accepts a command (list of strings) and runs it on the interpreter then saves it and calls the view function. '''
def view1(I): '''Print the stack to stdout using the pprint module.''' pprint.pprint(I[0]) print def nullView(I): '''"Do nothing" view.''' pass # An initial interpreter to use for spawning worlds. It has an empty # stack and whatever commands are defined by default in the library # module. ROOT = (), fill_tree((), words) class World(object): ''' Manage an interpreter, a view function, and serialization to a file or file-like object. This object takes a view function (any callable that accepts an interpreter) and optionally an initial interpreter and a save file. It creates a Serializer object to save commands and results, and it provides a step() method that accepts a command (list of strings) and runs it on the interpreter then saves it and calls the view function. ''' def __init__(self, view=nullView, initial=None, save_file=None):