On Mar 4, 1:14 am, Robert Bradshaw <[email protected]>
wrote:
> I think it's fair to test for strings first, trying to parse, before
> testing if it's an iterator. This is consistant with many other
> objects that try to "parse" their string representations.
>
> sage: ZZ['x']([1,2,3])
> 3*x^2 + 2*x + 1
> sage: ZZ['x']("123")
> 123
> sage: ZZ['x']("x^2 + 5")
> x^2 + 5

Indeed. It's not quit consistent with duck typing, but well ...

I guess matrix(S) would do:

  if isinstance(S,basestring):
    <do our best to parse S as a string rep of a matrix>
  else:
    try:
      V=iter(S)
      #figure out how to interpret the elements of V
      #(are they rows or elements?)
      #should we accept strings at this point?
      #the CSV example above indicates that with a known base ring,
      #allowing elements of V to be iterables of strings representing
elements
      #seems a good idea.
    except TypeError:
      #do whatever we do with non-iterable matrix initializers

-- 
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

Reply via email to