[PEAK] a trellis based project - and perhaps an issues

Roland Gude rol at ndgu.de
Fri Aug 24 10:26:31 EDT 2007

Hi everyone,

the very good quality of recent mailinglist updates, and the great
tutorial of trellis inspired me to start a small project which uses
trellis: http://bigpile.devjavu.com/projects/bigpile/wiki/pyLord

pyLord is a game in two senses. first: the software will be a
play-by-email game (or something similar), and second the scale of his
project is probably the right one to make this project a 'trellis
learning playground' at least for me.
Documentation is almost non existant at the current state, but as soon
as it is available, i am sure that the source code might contain a
couple of nice examples about trellis.

after 2 ays i have already encountered a strange behaviour of
trellis.List as a trellis.value()

given the following code 

>>> class ExampleClass(trellis.Component):
...    trellis.values(someList = trellis.List())

>>> e1 = ExampleClass()
>>> e2 = ExampleClass()

>>> e1.someList.append("this belongs to e1")
>>> e2.someList
["this belongs to e1"]

this shows that the two instances of ExampleClass end up using the same
instance of trellis.List() [and probably any other complex object like
dicts or own classes will end up shared if used in values]

a first soluion would be

>>> class ExampleClass2(trellis.Component):
...    trellis.rules(someList = lambda self: trellis.List())

>>> e1 = ExampleClass2()
>>> e2 = ExampleClass2()

>>> e1.someList.append("this belongs to e1")
>>> e2.someList

now every instance gets its own list.
however it is someList can not be reset anymore. in order to allow this
the following code is needed:

>>> class ExampleClass3(trellis.Component):
...    trellis.values(someList = None)
...    trellis.rules(someList = lambda self: trellis.List())

>>> e1 = ExampleClass3()
>>> e2 = ExampleClass3()

>>> e1.someList.append("this belongs to e1")
>>> e2.someList
>>> e1.someList = 12
>>> e1.someList

even though it is not a big deal, it is something one has to keep in
mind when creating trellis.Components. And i think it is something that
should be mentioned in the documentation.

keep up the great work.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20070824/ed4bd2fe/attachment.bin

More information about the PEAK mailing list