On Tuesday, January 17, 2012 6:06:25 PM UTC+8, luisfe wrote:

> On Jan 16, 5:53 pm, Ed Scheinerman <edward.sc...@gmail.com> 
> wrote: 
> > I'm confused by the fact that variables defined inside functions can 
> > "leak out" and become global variables. Here's what I've noticed. 
>
> The problem is twith the function var. According to its documentation: 
> (var?) 
>
> "The new variable is both returned and automatically injected 
> into the global namespace. If you need symbolic variable in 
> library code, it is better to use either SR.var() or SR.symbol()." 
>
> The var function is only intended to be used on an interactive session 
> by the user. If you need variables inside a function you need SR.var 
>

Yes, and I've always wondered why this is. How does it make anything easier 
or clearer or better for the interactive user that var() injects things 
into global scope? We found ourselves trying in vain to explain this to 
students several times when teaching our Sage-based undergraduate course 
last fall. (CCing to sage-devel, assuming I did this right...)

-Keshav

----
Join us in #sagemath on irc.freenode.net ! 

-- 
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
URL: http://www.sagemath.org

Reply via email to