Ok, <div><br></div><div>If I attach an item_type to the the list, I do not think I will able to use the native Python list, and should use a subclass instead. It is a bit heavyweight, especially when the intent of the use of the interface was documentation.<br>
<div><br></div><div>List and generators are very common in Python and are expressed in very few and clear characters, I thought there would be a shorter way to document their interfaces.</div><div><br></div><div>Thank you,</div>
<div><br><br><div class="gmail_quote">On Mon, Nov 8, 2010 at 2:24 PM, Tres Seaver <span dir="ltr"><<a href="mailto:tseaver@palladion.com">tseaver@palladion.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<div><div></div><div class="h5"><br>
On 11/08/2010 04:40 AM, Jean-Daniel wrote:<br>
> Hello,<br>
><br>
> I have two objects which interoperate to solve a sudoku: the Sudoku class<br>
> and a vector (a list actually) of generator functions. The Sudoku interface<br>
> is simple to write as it requires three functions and an attribute.<br>
><br>
> class ISudoku:<br>
><br>
> board = Attribute()<br>
><br>
> def free(col, line):<br>
> "frees the slot at position col, line"<br>
><br>
> def set(col, line, value):<br>
> "Sets the value in the slot at position col, line"<br>
><br>
> def candidates(col, line):<br>
> "Returns the candidate digits for the slot at position col,line"<br>
><br>
><br>
> But how to express "vector of generator functions" with Zope interfaces? I<br>
> want to express the possibility to access the vector object with<br>
> the [n] index notation, and this returns a function returning a generator<br>
> (an object with an iter and next function).<br>
><br>
> Thank you for your help,<br>
><br>
><br>
> PS: the vector of generator functions is the input of the algorithm called<br>
> "conjoin", used to solve the eight queen problem and knight's tour problem.<br>
> It is described in the Python sources<br>
> (Python-2.6.5/Lib/test/test_generators.py).<br>
><br>
> PPS: I say vector instead of list even when the vector is a list, because<br>
> "list" usually implies the possibility to append elements dynamically which<br>
> is not pertinent in this problem. The length of the vector won't change and<br>
> is equal to the number of slots on a sudoku board.<br>
<br>
<br>
</div></div>I would specify the contracts omething like so::<br>
<br>
<br>
class IVector(Interface):<br>
<br>
item_type = Attribute(u"Interface of items.")<br>
<br>
def __len__():<br>
""" Fixed length of vector.<br>
"""<br>
<br>
def __getitem__(index):<br>
""" Return the 'index'th item.<br>
<br>
Items conform to 'item_type'.<br>
<br>
'index' must be an integer between 0 and __len__() - 1,<br>
else raise IndexError.<br>
"""<br>
<br>
class IIterable(Interface):<br>
<br>
def __iter__():<br>
""" Return an iterator for this object.<br>
"""<br>
<br>
<br>
<br>
<br>
- --<br>
===================================================================<br>
Tres Seaver +1 540-429-0999 <a href="mailto:tseaver@palladion.com">tseaver@palladion.com</a><br>
Palladion Software "Excellence by Design" <a href="http://palladion.com" target="_blank">http://palladion.com</a><br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.10 (GNU/Linux)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
iEYEARECAAYFAkzX+ggACgkQ+gerLs4ltQ7WQwCeNu4lF+WysIjSYM86EjMhoPFH<br>
9ZsAnRB7T4Pz+bIVeVYxHbvRYaqN6iE7<br>
=U5bo<br>
-----END PGP SIGNATURE-----<br>
<br>
_______________________________________________<br>
Zope-Dev maillist - <a href="mailto:Zope-Dev@zope.org">Zope-Dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/zope-dev" target="_blank">https://mail.zope.org/mailman/listinfo/zope-dev</a><br>
** No cross posts or HTML encoding! **<br>
(Related lists -<br>
<a href="https://mail.zope.org/mailman/listinfo/zope-announce" target="_blank">https://mail.zope.org/mailman/listinfo/zope-announce</a><br>
<a href="https://mail.zope.org/mailman/listinfo/zope" target="_blank">https://mail.zope.org/mailman/listinfo/zope</a> )<br>
</blockquote></div><br></div></div>