Ah.  Thanks very much for that clarification.
Actually, my snippet illustrates the dilemma I was in.
t already has a value outside of f
executing f changes the value of t outside of f
that is what I would expect to happen if t were declared global in f, but I
thought t was local in f
I still love var, but now I know when to use SR.var instead
Carl

On Mon, Dec 21, 2015 at 9:49 AM, Jeroen Demeyer <[email protected]>
wrote:

> On 2015-12-21 16:38, Carl Eberhart wrote:
>
>> I admit I don't understand what is happening in the following snippit:
>>
>> def f():
>>      t=var('t')
>>      t=5
>>      a=2*t
>>      return a
>>
>
> Solution: never use var() in a function. If you do need a symbolic
> variable in a function (note that you don't in the snippet above), you can
> use SR.var() instead of plain var(). That behaves like var(), except that
> it does not change any global. Example:
>
> sage: SR.var('y')
> y
> sage: y
> NameError: name 'y' is not defined
>
> You can use it with explicit assignment:
>
> sage: y = SR.var('y')
> sage: y
> y
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sage-support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sage-support/G0vP7kulENg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" 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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to