Le 20/10/2016 à 13:15, John Cremona a écrit :
That is surely a bug.  I always assumed that the only trabformation
made when inputting a .sage file whe nit is converted to a .py file
was to apply the same preparsing as when you type into the command
line.  But that is not the case: note that

  preparse('0 = 42')

returns

'__tmp__=var("0"); Integer = symbolic_expression(Integer(42)).function(0)'

which fails because var() -- more specifically SR.var() -- tests its input.

Does anyon know why the .sage --> .py conversion is any different?
I can imagine that the reason is that in a long .sage file, one does not want to call the constructor for integers too many times.

Bruno


John

On 20 October 2016 at 10:00, Bruno Grenet <bruno.gre...@gmail.com> wrote:
Consider the following code:

0 = 42
print 0

If you write it into sage's ipython, it of course gives you an error. More
precisely, you get
ValueError: The name "0" is not a valid Python identifier.

But suppose you write it into a file bug.sage, and execute it using sage
bug.sage, you get 42! The explanation is actually pretty simple: when you
execute sage bug.sage, bug.sage is preparsed to bug.sage.py which is the
following:

# This file was *autogenerated* from the file bug.sage
from sage.all_cmdline import *   # import sage library

_sage_const_42 = Integer(42); _sage_const_0 = Integer(0)
_sage_const_0  = _sage_const_42
print _sage_const_0


Since 0 is replaced by _sage_const_0, you can affect any value to it.

Is this a known bug? Is there a way in Python to declare that _sage_const_i
is immutable?

I wanted to open a ticket, but as noticed by Dima, trac seems to be down...

Bruno


--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to