Open GoogleCodeExporter opened 9 years ago
The `with` statement seems to be worth to be used, the ideas above
look reasonable.
A general note: expr constructors should have
minimal number of keywords and only such keywords that do not
affect the results properties, e.g. the equality tests and hash
values must not depend on the values of keyword arguments.
The `using` kw is ok in this respect.
Few notes:
- I would suggest `context` instead of `using` kw and the default
value of global_context should be None. In fact, the kw itself should
have None as default value and the body of a constructor should find
the context from the parent namespace. For example:
def __new__(cls, *args, context=None):
if context is None:
context = get_object_by_name('__sympy_context__', global_context)
if context.simply_call_canonize_please:
return cls.canonize(*args)
else:
# try to handle nonstandard evaluation
The '__sympy_context__' variable would be set by the context manager
__enter__ method, for instance.
- The assumption contexts should support nesting, e.g.
with Assumptions(x>0):
with Assumptions(y>0):
suite
should work as
with(Assumptions(And(x>0, y>0))):
suite
The
with Assumptions(x>1):
with Assumptions(x>0):
suite
should work as
with Assumptions(x>1):
suite
but this should be resolved in Assumptions(And(x>0,x>1)) anyway.
Original comment by pearu.peterson
on 11 Dec 2007 at 10:48
> the default
> value of global_context should be None. In fact, the kw itself should
> have None as default value and the body of a constructor should find
> the context from the parent namespace. For example:
I'm not sure what the benefit is of this. The external global_context
object is accessed by default either way, only with None, more work
is required to access it. If global_context is passed as a default
parameter, only an attribute lookup on a local variable is needed in
the regular case. The user can still define a custom default context
in his own code if desired.
- The assumption contexts should support nesting
Agreed.
Original comment by fredrik....@gmail.com
on 11 Dec 2007 at 11:08
Yes, this is might be a bit premature technical detail
that is related to the (unsaid) idea of avoiding the
kw argument from the first place. I am sure that we
can figure out a proper (simple and efficient) way to deal
with this when starting to implement the contexts.
Original comment by pearu.peterson
on 11 Dec 2007 at 11:26
Original issue reported on code.google.com by
fredrik....@gmail.com
on 9 Dec 2007 at 6:10