Hi Stan,
On 25 Okt., 09:38, Stan Schymanski <[email protected]> wrote:
> This would sound like a flaw in the design to me, if there was no way
> to reconstruct a dictionary from its display form.
I couldn't disagree more.
First of all, it isn't just about dictionaries: You would have the
same problem with the printed form of units.energy.joule, which is
printed as "joule", but there is no symbol "joule" in the global name
space.
Why do I think that it is a very bad idea to require that the printed
form must always be valid input?
First of all, the global name space should not be too big. I simply
don't see why *all* contents of any module of Sage should by default
be put into the global name space. Not only would the name space be
too big, you would probably face a lot of name conflicts, and you are
likely to wait a long time for Sage to start.
Second, it frequently happens that two totally different objects have
the same string representation. For example:
sage: repr(GF(3)(1)) == repr(GF(2)(1))
True
sage: GF(3)(1) == GF(2)(1)
False
So, if you really want a printed form that allows for a reconstruction
of the printed object, you have to put *all* information on the object
- including all implementation details - into the printed form.
Do you really want this:
sage: P.<x,y> = QQ[]
sage: x
PolynomialRing(QQ,['x','y'],2,order='degrevlex').gen(0)
Or would you prefer that x is printed as x?
> In fact, it usually
> works (also for lists, arrays etc.), just not with units
That's wrong. It doesn't work *in general* (not only with units),
which is unavoidable, IMHO.
> I think that it would be useful
> to have a way to recover the input form of anything that was
> originally entered in textual form. Would it be possible to write a
> function for it?
There is such function: sage_input. However, it is far from perfect.
First of all, its doc string is misformatted - it'll look funny in the
reference manual. And it can not reconstruct even fairly simple
objects:
sage: sage_input??
sage: sage_input(GF(2)(1))
GF(2)(1)
sage: sage_input(x)
---------------------------------------------------------------------------
ValueError Traceback (most recent
call last)
...
ValueError: Can't convert x to sage_input form
> The reason why I need this is that I want to be able to easily and
> transparently import a summary of the results from one worksheet into
> another, in order to split up very long worksheets.
Why don't you simply save the results to a file, and load it into the
other worksheet?
That's to say, do
sage: save(udict, 'my_file.sobj')
in one sage session, and in the next sage session do
sage: udict = load('my_file.sobj')
Cheers,
Simon
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org