poeschko/Mathics — pull request #176 by bnjones (2013-11-20 21:26:20+00:00)
Title: WIP on context support

This is some work-in-progress code to support contexts. It's not passing all the tests yet, and I'm not completely happy with it, but it'd be good to know if the approach I've taken is workable.

What I've done is:

- Made symbol names include the full context they're in (to avoid breaking the assumption in Python code that symbols that compare equal are the same). I'd guess that this is the most controversial part - I couldn't think of a reasonably low-impact alternative, so I think this could be the least bad option.
- Added some code to `Definitions` to look up symbol names in `$ContextPath`, and shorten them if they're accessible.

Most of the change involves qualifying with ``` System` ``` all the hardcoded symbol names in the source, except for:

- `Symbol("x"), Expression('x', ...), has_form('x', ...)` -> these all assume ``` System`x ``` if they're given a string without a context mark. This was just to reduce the number of cases which needed ``` System` ```.
- `class MyBuiltin(Builtin)` - this creates ``` System`MyBuiltin ``` unless the class changes the `context` attribute.
- Docstrings -> these are parsed with a dummy `Definitions` instance which says that every symbol is in ``` System` ```.

Some stuff that I haven't tried to do yet:

- Shadowing warnings
- BeginPackage, EndPackage etc