Dear Amritanshu,

On Thu, Jun 13, 2013 at 10:19:32PM -0700, Amritanshu Prasad wrote:
>    I am trying to define a class with parent EnumeratedSets whose constructor
>    takes a list as an input.
>    I tried:
>    class MyExample(UniqueRepresentation, Parent):
>        def __init__(self, input):
>            self._input = input
>        def __repr__(self):
>            return str(self._input)
>    but when I said
>    MyExample([2,2])
>    I got:
> 
>  Traceback (most recent call last):
>  TypeError: unhashable type: 'list'
> 
>    I would be grateful if someone could explain why this happens, and how to
>    get around it.

Good question! Which luckily has a good answer :-) See the section
"Argument preprocessing" in the documentation of CachedRepresentation:

        
http://sagemath.org/doc/reference/structure/sage/structure/unique_representation.html

or equivalently:

        sage: UniqueRepresentation??


By the way: in your __init__ you probably want a line of the form:

        Parent.__init__(self, category=EnumeratedSets())

and __repr__ should be _repr_. For an example, see:

    sage: C = FiniteEnumeratedSets().example()
    sage: C
    An example of a finite enumerated set: {1,2,3}
    sage: C??

Kind regards,
                                Nicolas
--
Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net>
http://Nicolas.Thiery.name/

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-combinat-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-combinat-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-combinat-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to