#13586: BuiltinFunction expects to be instantiated only once
-------------------------------------+--------------------------------------
       Reporter:  burcin             |         Owner:  burcin             
           Type:  defect             |        Status:  positive_review    
       Priority:  major              |     Milestone:  sage-5.5           
      Component:  symbolics          |    Resolution:                     
       Keywords:  symbolic function  |   Work issues:                     
Report Upstream:  N/A                |     Reviewers:  Karl-Dieter Crisman
        Authors:  Burcin Erocal      |     Merged in:                     
   Dependencies:                     |      Stopgaps:                     
-------------------------------------+--------------------------------------
Changes (by kcrisman):

  * status:  needs_review => positive_review
  * reviewer:  => Karl-Dieter Crisman


Old description:

> From [[http://ask.sagemath.org/question/1843/weird-behavior-
> builtinfunction|this ask.sagemath.org question]]:
>
> {{{
> sage: from sage.symbolic.function import BuiltinFunction
> sage: class AFunction(BuiltinFunction):
> ....:         def __init__(self, name, exp=1):
> ....:             self.exponent=exp
> ....:         BuiltinFunction.__init__(self, name, nargs=1)
> ....:     def _eval_(self, arg):
> ....:             return arg**self.exponent
> ....:
> sage: p2 = AFunction('p2', 2)
> sage: p2(x)
> x^2
> sage: p3 = AFunction('p3', 3)
> sage: p3(x)
> x^2
> }}}
>
> ATM, we only allow a `BuiltinFunction` to be instantiated once.

New description:

 From [[http://ask.sagemath.org/question/1843/weird-behavior-
 builtinfunction|this ask.sagemath.org question]]:

 {{{
 sage: from sage.symbolic.function import BuiltinFunction
 sage: class AFunction(BuiltinFunction):
 ....:         def __init__(self, name, exp=1):
 ....:             self.exponent=exp
 ....:         BuiltinFunction.__init__(self, name, nargs=1)
 ....:     def _eval_(self, arg):
 ....:             return arg**self.exponent
 ....:
 sage: p2 = AFunction('p2', 2)
 sage: p2(x)
 x^2
 sage: p3 = AFunction('p3', 3)
 sage: p3(x)
 x^2
 }}}

 ATM, we only allow a `BuiltinFunction` to be instantiated once.


 ----

 Apply [attachment:trac_13586-builtin_function.patch].

--

Comment:

 Nice work, Burcin.  I guess this doesn't stop someone from doing
 {{{
 sage: p4 = AFunction('p2',3)
 }}}
 but I suppose that is the user's problem, since they are redefining the
 name `p2`.  Similarly, is this (new behavior, I think) ok?  I think so,
 but just want to make sure.
 {{{
 sage: class MyFunction(BuiltinFunction):
 ....:     def __init__(self,name):
 ....:         self.exponent=1
 ....:         BuiltinFunction.__init__(self,name,nargs=1)
 ....:     def _eval_(self,arg):
 ....:         return arg**self.exponent
 ....:
 sage: MyFunction('p')
 p
 sage: p = MyFunction('p')
 sage: p
 p
 sage: p(2)
 2
 sage: p(3)
 3
 sage: q = MyFunction('q')
 sage: q(3)
 3
 sage: p
 p
 sage: q
 q
 }}}

 ----

 Patchbot: Apply trac_13586-builtin_function.patch

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13586#comment:2>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to