#12978: conditionally_defined decorator for methods and other attributes
-------------------------------------------------+-------------------------
Reporter: nthiery | Owner: jason
Type: enhancement | Status: new
Priority: major | Milestone: sage-
Component: misc | wishlist
Keywords: categories, | Resolution:
conditionally_defined | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: #15056 | Stopgaps:
-------------------------------------------------+-------------------------
Changes (by SimonKing):
* dependencies: => #15056
Old description:
> Goal: implement conditionally defined methods and nested classes:
>
> Typical use cases:
> {{{
> class A(...):
>
> ...
>
> @conditionaly_defined(has="product_with_basis")
> def product(self):
> ... build the product by bilinearity
>
> @conditionaly_defined(lambda self: self.q() == 2):
> class MyBasis:
> ...
> }}}
>
> Then, for ``a`` an instance of ``A``, the above condition would be
> evaluated at runtime, when a.product is first accessed, like for lazy
> attributes.
>
> That's a feature we used a lot in the category code in MuPAD.
New description:
Goal: implement conditionally defined methods (and nested classes?):
Typical use cases:
{{{
class A(...):
...
@conditionaly_defined(has="product_with_basis")
def product(self):
... build the product by bilinearity
# Would be nice to have, but seems to be not easily possible
@conditionaly_defined(lambda self: self.q() == 2):
class MyBasis:
...
}}}
Then, for ``a`` an instance of ``A``, the above condition would be
evaluated at runtime, when a.product is first accessed, like for lazy
attributes.
That's a feature we used a lot in the category code in MuPAD.
--
Comment:
For now, I think nested classes won't work.
Replying to [comment:14 SimonKing]:
> In any case, I think it would be more interesting to be able to
conditionally define a cached method, in ''both'' versions I suggested:
> {{{
> @cached_method
> @conditionally_defined(...):
> def meth(...):
> ...
> }}}
> being a cached method whose underlying implementation is conditional,
and
> {{{
> @conditionally_defined(...):
> @cached_method
> def meth(...):
> ...
> }}}
> being a cached method that is only used conditionally.
That's why I add #15056 as a dependency.
--
Ticket URL: <http://trac.sagemath.org/ticket/12978#comment:15>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.