I think global=False would be a nice option, also because there seem to be more differences between a symbolic variable created using "var" and "new_var" than just the scope; I noticed that while "var" creates a symbolic variable, "new_var" creates an expression (class 'sage.symbolic.expression.Expression') which cannot be used in the same way, e.g. solve_mod(3*x == 1, 10) is ok for x created using "var" but causes an error for x created using "new_var".
On Jun 16, 9:53 pm, Utpal Sarkar <doe...@gmail.com> wrote: > Thanks! > > On Jun 16, 9:30 pm, William Stein <wst...@gmail.com> wrote: > > > On Tue, Jun 16, 2009 at 9:12 PM, Utpal Sarkar<doe...@gmail.com> wrote: > > > > Hi, > > > > It looks like locally defined symbolic variables are always global, in > > > particular they overwrite globally defined variables of the same name: > > > sage: d = 0 > > > sage: def f(): > > > ....: d = var('d') > > > ....: d = 1 > > > ....: > > > sage: d > > > 0 > > > sage: f() > > > sage: d > > > d > > > (I put the d = 1 in the function definition to show the difference in > > > behaviour) > > > Use new_var: > > > sage: d=0 > > sage: def foo(n): > > ... d = sage.calculus.var.new_var('d') > > ... print d^n > > ... > > ... > > sage: foo(10) > > d^10 > > sage: d > > 0 > > > Maybe var(global=False) should be an option? > > > William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---