<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Five-minute Multimethods In Python (using dispatch)</title>
	<atom:link href="http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/feed/" rel="self" type="application/rss+xml" />
	<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/</link>
	<description>Bob's Rants</description>
	<pubDate>Thu, 24 Jul 2008 01:13:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Paul Moore</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1296</link>
		<dc:creator>Paul Moore</dc:creator>
		<pubDate>Wed, 13 Apr 2005 14:29:26 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1296</guid>
		<description>I don't like the string forms either. The "lower-level" API Philip refers to looks reasonable to me (although I'm not clear how the x/y in Philip's comment relate to the a/b in the parameters...)

So far, I've only really watched the development of the generic function stuff, never used it, but my instinct says that I would use the "lower-level" API if at all possible, and avoid the string form whenever I could. If Python supported an "expression literal" form which was used here instead of strings, I'd be a lot happier. No idea why. Maybe it's something as silly as the syntax highlighting my editor applies...</description>
		<content:encoded><![CDATA[<p>I don&#8217;t like the string forms either. The &#8220;lower-level&#8221; API Philip refers to looks reasonable to me (although I&#8217;m not clear how the x/y in Philip&#8217;s comment relate to the a/b in the parameters&#8230;)</p>
<p>So far, I&#8217;ve only really watched the development of the generic function stuff, never used it, but my instinct says that I would use the &#8220;lower-level&#8221; API if at all possible, and avoid the string form whenever I could. If Python supported an &#8220;expression literal&#8221; form which was used here instead of strings, I&#8217;d be a lot happier. No idea why. Maybe it&#8217;s something as silly as the syntax highlighting my editor applies&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phillip J. Eby</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1116</link>
		<dc:creator>Phillip J. Eby</dc:creator>
		<pubDate>Thu, 31 Mar 2005 23:16:43 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1116</guid>
		<description>Guido, you were the one who suggested using strings for this, in a message on Python-Dev long ago.  At least, I recall you saying that strings were the right way to express Python code within Python, when somebody was asking for a block syntax.  But that was a long time ago and perhaps you've changed your mind since. One alternative I considered was to use lambda: and getsource(), but getsource() doesn't seem to grok lambdas.

In any case, the &lt;code&gt;@foo.when(Signature(x=int,y=int))&lt;/code&gt; example I showed in the comments on your blog is functionally equivalent to the isinstance() string form, and you can do &lt;code&gt;Signature(x=str,y=str) &#124; Signature(x=unicode,y=unicode)&lt;/code&gt; to "or" signatures together.  So, if you prefer not to use strings for when() conditions, you can construct predicates and signatures using the lower-level dispatch API.  (That is, you can directly build the structure that the parser would build from a string.)</description>
		<content:encoded><![CDATA[<p>Guido, you were the one who suggested using strings for this, in a message on Python-Dev long ago.  At least, I recall you saying that strings were the right way to express Python code within Python, when somebody was asking for a block syntax.  But that was a long time ago and perhaps you&#8217;ve changed your mind since. One alternative I considered was to use lambda: and getsource(), but getsource() doesn&#8217;t seem to grok lambdas.</p>
<p>In any case, the <code>@foo.when(Signature(x=int,y=int))</code> example I showed in the comments on your blog is functionally equivalent to the isinstance() string form, and you can do <code>Signature(x=str,y=str) | Signature(x=unicode,y=unicode)</code> to &#8220;or&#8221; signatures together.  So, if you prefer not to use strings for when() conditions, you can construct predicates and signatures using the lower-level dispatch API.  (That is, you can directly build the structure that the parser would build from a string.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guido van Rossum</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1115</link>
		<dc:creator>Guido van Rossum</dc:creator>
		<pubDate>Thu, 31 Mar 2005 22:27:13 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1115</guid>
		<description>Yes, Phillip.

I have to say, I just cringe when I see any kind of API that takes a string containing Pythonesque syntax a la our where() predicate.  But we should probably take that offline (and I understand the constraints under which you are working.)</description>
		<content:encoded><![CDATA[<p>Yes, Phillip.</p>
<p>I have to say, I just cringe when I see any kind of API that takes a string containing Pythonesque syntax a la our where() predicate.  But we should probably take that offline (and I understand the constraints under which you are working.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phillip J. Eby</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1114</link>
		<dc:creator>Phillip J. Eby</dc:creator>
		<pubDate>Thu, 31 Mar 2005 19:00:38 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1114</guid>
		<description>Hi Guido.  Bob has now added a spelled-out version of your example to his article; is that what you were asking for?</description>
		<content:encoded><![CDATA[<p>Hi Guido.  Bob has now added a spelled-out version of your example to his article; is that what you were asking for?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guido van Rossum</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1113</link>
		<dc:creator>Guido van Rossum</dc:creator>
		<pubDate>Thu, 31 Mar 2005 18:00:34 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1113</guid>
		<description>Phillip, would you mind showing a more "natural" example using PyProtocols, e.g. one that requires separate initial registration and isinstance?</description>
		<content:encoded><![CDATA[<p>Phillip, would you mind showing a more &#8220;natural&#8221; example using PyProtocols, e.g. one that requires separate initial registration and isinstance?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phillip J. Eby</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1112</link>
		<dc:creator>Phillip J. Eby</dc:creator>
		<pubDate>Thu, 31 Mar 2005 17:55:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1112</guid>
		<description>I think it's important to point out that all of the complexity in this code comes from 1) emulating Guido's "implicit" API where the multimethod is automatically created upon first definition, and 2) implementing exact type matching instead of using isinstance().  Without #1, most of the 'register' function wouldn't be needed, and without #2, the Getattr/Pointer stuff would be unnecessary.  So, with the dispatch framework it's actually *harder* to create a crippled and implicit version of the API.  :)

Part of the reason I point this out is so that people stumbling across this page don't end up thinking that Guido's code is "better" than using the dispatch module, or -- even worse! -- they actually use this code.

If you really want the semantics of Guido's example and you're using PyProtocols, you should use &lt;code&gt;@foo.when("type(a) is int and type(b) is int")&lt;/code&gt; and not reimplement all these wheels.  And if you want multiple signatures for a single method, then &lt;code&gt;@foo.when("type(a) is str and type(b) is str or type(a) is unicode and type(b) is unicode")&lt;/code&gt; also works as intended.  There's then no need for last-method attribute hacks or stacked decorators.</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s important to point out that all of the complexity in this code comes from 1) emulating Guido&#8217;s &#8220;implicit&#8221; API where the multimethod is automatically created upon first definition, and 2) implementing exact type matching instead of using isinstance().  Without #1, most of the &#8216;register&#8217; function wouldn&#8217;t be needed, and without #2, the Getattr/Pointer stuff would be unnecessary.  So, with the dispatch framework it&#8217;s actually *harder* to create a crippled and implicit version of the API.  :)</p>
<p>Part of the reason I point this out is so that people stumbling across this page don&#8217;t end up thinking that Guido&#8217;s code is &#8220;better&#8221; than using the dispatch module, or &#8212; even worse! &#8212; they actually use this code.</p>
<p>If you really want the semantics of Guido&#8217;s example and you&#8217;re using PyProtocols, you should use <code>@foo.when("type(a) is int and type(b) is int")</code> and not reimplement all these wheels.  And if you want multiple signatures for a single method, then <code>@foo.when("type(a) is str and type(b) is str or type(a) is unicode and type(b) is unicode")</code> also works as intended.  There&#8217;s then no need for last-method attribute hacks or stacked decorators.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Ippolito</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1110</link>
		<dc:creator>Bob Ippolito</dc:creator>
		<pubDate>Thu, 31 Mar 2005 03:15:42 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1110</guid>
		<description>Expanded</description>
		<content:encoded><![CDATA[<p>Expanded</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guido van Rossum</title>
		<link>http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/#comment-1109</link>
		<dc:creator>Guido van Rossum</dc:creator>
		<pubDate>Thu, 31 Mar 2005 03:01:55 +0000</pubDate>
		<guid isPermaLink="false">/?p=125#comment-1109</guid>
		<description>What's hiding behind those "import *" statements?  Could you expand those?</description>
		<content:encoded><![CDATA[<p>What&#8217;s hiding behind those &#8220;import *&#8221; statements?  Could you expand those?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
