#7482: provide a mode so that undeclared variables magically spring into 
existence
and object oriented notation is not necessary
---------------------------+------------------------------------------------
   Reporter:  was          |       Owner:  tbd     
       Type:  enhancement  |      Status:  new     
   Priority:  major        |   Milestone:  sage-4.3
  Component:  misc         |    Keywords:          
Work_issues:               |      Author:          
   Reviewer:               |      Merged:          
---------------------------+------------------------------------------------

Comment(by was):

 I have created a "mock up" of the above functionality, for people to play
 with, which doesn't even require applying a patch.  Just paste the
 following into a Sage notebook cell and press shift-enter:
 {{{
 class MagicVar(Expression):
     def __call__(self, *args, **kwds):
         return args[0].__getattribute__(str(self))(*args[1:], **kwds)

 class MagicNames:
     def eval(self, s, globals, locals=None):
         x = preparse(s).strip()
         y = x.split('\n')
         if len(y) == 0:
             return ''
         s = '\n'.join(y[:-1]) + '\n'
         t = y[-1]
         try:
             z = compile(t + '\n', '', 'single')
         except SyntaxError:
             s += '\n' + t
             z = None
         while True:
             try:
                 self._eval_code(s, z, globals)
             except NameError, msg:
                 nm = msg.args[0].split("'")[1]
                 globals[nm] = MagicVar(SR, var(nm))
             else:
                 return ''

     def _eval_code(self, s, z, globals):
         eval(compile(s, '', 'exec'), globals, globals)
         if z is not None:
             eval(z, globals)

 magic = MagicNames()
 }}}

 Now if you put %magic at the top of an input cell, then symbolic variables
 magically spring into life, and object oriented notation is not necessary.
 There isn't an easy way to make this permanent for all cells in a
 worksheet (without putting %magic) without actually changing the sage
 library with a patch.  This is because of a major annoying mistake I found
 just now (see #7483).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7482#comment:1>
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].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=.


Reply via email to