On 5/22/07, Michel <[EMAIL PROTECTED]> wrote:
> > I'm concerned that your proposal, if I understand it correctly,
> > will make it difficult to avoid infinite loops.  Could you flesh
> > out your proposal more, and specifically address issues
> > involving infinite loops?
>
> I guess this was more of an idea than a proposal.  But given
> the rethinking of the coercion model it is perhaps appropriate
> to raise it.
>
> To address your concerrn wouldn't it be sufficient to specify that
>
> _noncanonical_into_
>
> should *not* call R(self). Or if it *really* wants to then it should
> do R._call_(self) (single underscore).
>
> In the examples I have in mind things are pretty simple.
> Constant diagonal matrices --> base ring.
> Fraction field element-> base ring (if the denominator is a unit)
> Constant polynomials -> base ring.
> Field extension -> base field (if applicable)
>

Maybe we could define a method:

  def _scalar_(self):
        """
        If self is a scalar, i.e., naturally makes sense as an element of the
        base ring, then return that element as an element of the base ring.
        This function *must* not return an element with the same parent
        as self.
        """
        raise TypeError

method in Element, and in each of the above types (that you list)
we could implement it.  Then we would make sure all ring __call__
methods try calling _scalar_ on their input if all else fails.

def __call__(self, x):
      ... stuff ...
      try:
          return self(x._scalar_())       # I am very scared of recursion.

Feel free to try to shoot down this proposal.  The name scalar might
be wrong.

In any case, I full agree that there is a problem to be addressed,
and the current framework doesn't provide a good way to address it.

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to