Re: Replacing Axiom Lists with a new list of Items

Jean-Paul Calderone <[email protected]> Sat, 1 Jul 2006 15:44:56 -0400
Newsgroups gmane.comp.python.quotient.dev
Message-ID <20060701194456.29014.1317836301.divmod.quotient.18176@ohm>
On Sun, 2 Jul 2006 04:25:11 +0900, Robert Gravina <[email protected]> wrote:
>>On Sun, 2 Jul 2006 03:12:30 +0900, Robert Gravina  <[email protected]> 
>>wrote:
>>>In Axiom, is there any quick way to update the contents of one  List  with 
>>>the contents of another, so that existing items can be  updated,  non 
>>>existing ones deleted, and new ones added?
>>
>>In general, it is probably best to avoid axiom.sequence.List.  It was
>>written as part of an axiom tutorial and it demonstrates various APIs
>>pretty well, but it doesn't actually perform very well and it usually
>>does more work than you actually need.
>
>How else can I give Item objects collections of other Items then? In  all 
>the examples I've seen, Lists were used.
>>That said, there is no simple efficient way to perform the operation
>>you describe on any other kind of set or sequence in Axiom.

Using a simpler one-to-many relation than the one List uses.  For example:

class ContainerRelation(Item):
    container = reference()
    containee = reference()

class ContainerItem(Item):
    def add(self, item):
        ContainerRelation(store=self.store,
                          container=self,
                          containee=item)

    def __iter__(self):
        contents = self.store.query(
            ContainerRelation,
            ContainerRelation.container == self)
        for relation in contents:
            yield relation.containee
            
Jean-Paul