>
> Good point.  It turns out to be much harder if we don't just assume numbers.
>  I guess one way to do it would be to construct a parse tree using the
> python parsing, except, of course, that semicolons make [1 2 3; 4 5 6] not
> valid syntax, though I suppose we could replace semicolons and newlines with
> "][" and then filter out empty lists.  Spaces also would be problem in
> constructing a parse tree, since [1 2] isn't valid syntax.
>
> So yeah, expanding the preparser for this very common situation (easily
> creating a doubly-nested list) is starting to look more like a good idea.
>
> If we expanded the preparser, would [1 2; 3 4] create a matrix or just a
> doubly-nested list?  I can see arguments both ways, and this is where Nils
> point really hits home.  Almost always, I want matrices over QQ, but [1 2; 3
> 4] won't naturally create a matrix over QQ.  On the other hand, typing
> matrix(QQ, [1 2; 3 4]) seems to take the fun out of the syntax, since it's
> not too much easier than matrix(QQ, [[1,2], [3,4]])

Some of the code used to manage this:

sage: M = matrix(2,2,[1,2,3,4])
sage: PM = pari(M)
sage: PM
[1, 2; 3, 4]
sage: PM.sage()
[1 2]
[3 4]

could perhaps be reused like this:

sage: s = "[1,2;3,4]"
sage: pari(s).sage()
[1 2]
[3 4]
sage: s = "[1.1,2.2;3.3,4.4]"
sage: pari(s).sage()
[1.1000000000000000000000000000000000000
2.2000000000000000000000000000000000000]
[3.3000000000000000000000000000000000000
4.4000000000000000000000000000000000000]

so we are using the pari parser to construct a pari matrix, which then
knows how to be converted into sage.

John

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to