On Wed, Jan 7, 2009 at 6:52 AM, Jason Grout <jason-s...@creativetrax.com> wrote:
>
> thelamecamel wrote:
>> Thanks all for speedy help!
>>
>> On Jan 7, 4:25 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
>>> These are not the right way to do this, but they seem to give results
>>> for right now, at least until someone fixes this:
>>>
>>> sage: a=mathematica([1,2,3])
>>> sage: [a[i] for i in range(1,a.Length()+1)]
>>> [1, 2, 3]
>>>
>>> Or
>>>
>>> sage: a=mathematica(slist)
>>> sage: a._Expect__sage_list
>>> [1, 2, 3]
>>
>> I think I can get a variant of the first tactic working in my program
>> - I've actually dealing with non-rectangular multidimensional
>> mathematica lists, e.g. {1, {2, 3}}, which are not handled by either
>> approach.  By explicitly coding for the structure of my lists I think
>> I can get it working in my case; but it would be great if sage could
>> handle nested lists such as this - it looks like a case of just
>> replacing curly brackets by square ones.
>
>
> Yes, you can get the above to work with nested lists using recursion.
> Your other idea is good too (well, again, not the "right" way to do it,
> but until someone fixes it).

If all the entries in the list were integers or rationals, then doing
what you suggest below would be the right way, and would be the
fastest way to convert from mathematica back to sage.   The technique
below is a problem if the entries in the list of lists are funny
mathematica objects that can't be eval'd in sage.

> Note that there are security implications
> in the code below since we call eval.
>
> sage: a=mathematica([1,2,[3,4]])
> sage: sage_eval(repr(a).replace('{','[').replace('}',']'))
> [1, 2, [3, 4]]
>
> Jason
>
>
>
>
>
>
>>
>> Thanks again,
>> Felix
>> >
>>
>
>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

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

Reply via email to