RootFrame
The root/global frame object. This holds all the function definitions, and global variables. All the algorithms end up being different than for Frame, so they don't even inherit from each other, though they present the same interface. Huh.
The RootFrame class is accessible via the pylogo.interpreter module.
Attributes
a special_forms
{'ask': <function special_tell at 0xb745e3e4>, 'for': <function special_for at 0xb745e3ac>, 'local': <function special_local at 0xb745e374>, 'localmake': <function special_localmake at 0xb745e304>, 'make': <function special_make at 0xb745e2cc>, 'makeattr': <function special_makeattr at 0xb745e41c>, 'tell': <function special_tell at 0xb745e3e4>, 'to': <function special_to at 0xb745e33c>}
Methods
f push_tokenizer(self, tokenizer) ...
You can stack up multiple tokenizers, as the interpreter goes from evaluating a file to a list to a sublist, etc. New interpreters are created for a new scope.
f expr_top(self) ...
Unlike expr(), this ignores empty lines; should only be used in top-level expressions (including expressions taken from lists).
f expr_without_error(self) ...
Get a full expression from the tokenizer, execute it, and return the value.
- expr ::= exprInner <operator> exprInner
- ::= exprInner
f expr_inner(self, apply=None, get_function=None, get_variable=None) ...
An 'inner' expression, an expression that does not include infix operators.
exprInner ::= <literal int or float> ::= '-' expr ::= '+' expr ::= ('"' or 'QUOTE') <word> ::= ':' <word> ::= MAKE (':' or '"') <word> expr ::= MAKE <word> expr ::= TO <to expression> ::= '[' <list expression> ']' ::= '(' <word> <expr> ... <expr> ')' ::= <word> <expr> ... <expr>
Things to note:
- MAKE :x 10, MAKE "x 10, and MAKE x 10 all work equivalently (make is a special form, unlike in UCBLogo).
- <list expression> is a nested list of tokens.
- <to expression> is TO func_name var1 var2 <int>, where <int> is the default arity (number of variables). Variables, like with make, can be prefixed with : or ", but need not be.
- () is not used to force precedence, but to force execution with a specific arity. In other words, () works like Lisp.
f special_make(self, greedy) ...
The special MAKE form (special because a variable in the first argument isn't evaluated).
f special_local(self, greedy) ...
The special LOCAL form (with unevaluated variables). (Should this be generally greedy?)
f apply(self, func, args) ...
Apply the args to the func . If the function has an attribute logo_aware , which is true, then the first argument passed to the function will be this interpreter object. This allows special functions, like IF or WHILE, to manipulate the interpreter.
f import_function(self, import_function, names=None) ...
Inputs the function func into the namespace, using the name it was originally defined with. The special attribute logo_name overrides the function name, and aliases provides abbreviations for the function (like FD for FORWARD).
f import_module(self, mod) ...
Import a module (either a module object, or the string name of the module), moving all of its exported functions into the current namespace (nested namespaces are not supported).
If a file defs/modulename.logodef exists, it will be loaded to find extra information about the module. This file contains one line for each annotated function (# or ; for comment lines). See loadDefs for more.
f load_defs(self, filename) ...
Load function definitions from a file. This file should have one function annotation on a line (lines starting with # or ; are comments).
Each line starts with the function name and a color. A star (*) means that the original function name should not be used. A word like arity:N will set the default arity of the function to N (if the default arity differs from the number of arguments the function takes). Other words are interpreted as aliases for a function. E.g.:
forward: fd up: * penup pu ; RGB arguments only: color: arity:3
f import_logo(self, filename) ...
Import a logo file. This executes the file, including any TO statements, putting everything into the normal namespace/scope.
See the source for more information.