file objects nowadays have ".closed" and ".mode" attributes, but the point is -- <br>the dispatch mechanism should be able to put constraints on not only on the <br>*type*, but on the *state* as well -- so once we have multi-dispatch, we
<br>wouldn't need to "manually" check the state of the arguments. <br><br>we want to be able to express that in the dispatch itself. imagine this:<br><br>def factorial(n):<br> if n < 0:<br> raise ValueError
<br> if n < 2:<br> return 1<br> return n*factorial(n-1)<br><br>where i want to write it as<br><br>@dispatched<br>def factorial(n : (lambda n: 0 <= n < 2)):<br> return n<br><br>@dispatched<br>
def factorial(n : (lambda n: n >= 2)):<br>
return n * factorial(n-1)<br><br>also note that no case is defined for (n < 0), which makes it an exception<br>automatically. this makes it very much like Haskell's pattern matching.<br>
<br>you can see some more info at <a href="http://en.wikipedia.org/wiki/ERights">http://en.wikipedia.org/wiki/ERights</a> <br>(look for "guard")<br><br><br>-tomer<br><br><div><span class="gmail_quote">On 1/17/07,
<b class="gmail_sendername">Bill Janssen</b> <<a href="mailto:janssen@parc.com">janssen@parc.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Of course, the purpose of using ABCs is to allow easy inspection of<br>the capabilities of an object, and for some objects, the state can be<br>an important part. But don't be misled to confuse ABCs with simply<br>type-based function dispatch. They're useful for other things as
<br>well.<br><br>I think that stateful value types should probably have, as you say,<br>mechanisms for inspecting that state. For instance, the current<br>"file" type has a "closed" attribute, doesn't it?
<br><br>Bill<br></blockquote></div><br>