#17958: implement declare_var, deprecate (None)var
-----------------------------+------------------------
       Reporter:  rws        |        Owner:
           Type:  defect     |       Status:  new
       Priority:  major      |    Milestone:  sage-6.6
      Component:  symbolics  |   Resolution:
       Keywords:             |    Merged in:
        Authors:             |    Reviewers:
Report Upstream:  N/A        |  Work issues:
         Branch:             |       Commit:
   Dependencies:             |     Stopgaps:
-----------------------------+------------------------

Comment (by nbruin):

 Replying to [comment:50 vbraun]:
 > {{{
 > sage: SR.inject_variables('x, y')
 > sage: SR.inject_variables('x', 'y')   # strings to variable names
 > sage: SR.inject_variables('x{i}', i=range(10))    # use keyword
 arguments to format
 > sage: SR.inject_variables(ex)     # inject all of ex.variables()
 > }}}
 Something like that would work, but probably not under that name. The
 method already exists on `SR` by inheritance (and doesn't work), and the
 signature you're proposing is incompatible with the one on other rings.

 Injecting in general isn't really a method that belongs on the object,
 since the object doesn't naturally have access to the dictionary into
 which these things should be injected. It's really more the task of a REPL
 utility function. In which case the spelling
 {{{
 inject_generators(QQ['x'])
 }}}
 would make more sense. The magic of figuring out into which dictionary the
 bindings should be injected is compartmentalized into a single function
 which could be implemented basically as
 {{{
 def inject_generators(parent):
     D={repr(a): a for a in parent.gens()}
     print "defining ",D.keys()
     user_globals.update(D)
 }}}
 This probably much nicer than scattering references to user_globals all
 over the place (we'd probably want to add some sanity checks to prevent
 this from inserting objectionable bindings).

 For symbolic binding we could then have something along the lines of
 {{{
 def inject_symbols(*args):
     user_globals.update({ repr(a):a for e in args for a in e.variables()})
 }}}

 Interfacing via `%var` is then an additional measure.

 In short, what we seem to be converging towards is:
  - deprecate `sage.calculus.var.var` (but keep supporting it; after a
 while probably do adorn it with a deprecation warning)
  - support symbolic variable injection via a special `%var` directive
 (which saves quotes too!) -- Is the `%` a problem? We'd need to make
 doctests aware of it.
  - have `SR.var(...)` as general symbol creation (which we already have).

 There is some further rationalization around injection behaviour possible.

--
Ticket URL: <http://trac.sagemath.org/ticket/17958#comment:54>
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/d/optout.

Reply via email to