On Fri, Jun 19, 2015 at 5:45 PM, Nils Bruin <nbr...@sfu.ca> wrote: > On Wednesday, June 17, 2015 at 7:48:15 AM UTC-7, Darij Grinberg wrote: >> >> Unfortunately, currently the ducktyping is not just in the matrix >> constructor; it is split across the three stations I mentioned (matrix >> constructor, matrix space, matrix class). Apparently every single of >> our matrix classes has its own way of recognizing "scalar matrix" >> input (that very matrix(n, n, c) syntax that has caused the present >> discussion), apparently written by different people (since the error >> messages differ). I suspect there is no way for sufficiently generic >> code to sidestep all of the ducktyping at the present time, and this >> is just bad. > > > Unfortunately, this is invited by the design of sage: The "__call__" entry > on a parent is the main interface to element construction and since this is > "conversion", all kinds of wild input are allowed.
I think this is the main design mistake here. > Do we have a default > place where a rigid-interfaced element constructor goes? Would providing one > improve the situation? I suspect not, since that just adds another corridor > to the maze. I am used to such constructors being implemented in methods that begin with "from_" (such as "from_permutation", "from_scalar", etc.). Probably not really standardized, but still better than everything heaped together in one method. > Perhaps sane, but also hardly necessary. One can immediately rewrite > > matrix(n,m,f) -> matrix(n,m,[f(i,j) for i in range(n) for j in range(m)]) One can, but does one want to? > [5] matrix([ring],[n,[m]],<mapping type>) > > which should take precedence over [3] and [4] > > Luckily polynomials, while allowing indexing, don't implement the full > Mapping protocol, so at least they won't interfere with [5]. What is the full Mapping protocol? Is it this? https://docs.python.org/2/library/collections.html#collections.Mapping The doc doesn't make me much wiser. What Sage types implement this protocol, or claim to? Also, I don't think we can assume that elements of a ring don't implement some protocol, whatever the protocol is. Free module elements, for example, are fairly good at pretending to be vectors and/or dictionaries. Best regards, Darij -- 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 http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.