<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Visitor pattern with closures</title>
	<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/</link>
	<description>Alex Miller's technical blog</description>
	<pubDate>Sun, 27 Jul 2008 01:16:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Alex Miller - Dynamic visitor builder with closures</title>
		<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32863</link>
		<pubDate>Sun, 16 Mar 2008 08:05:27 +0000</pubDate>
		<guid>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32863</guid>
					<description>[...] &amp;#171; Visitor pattern with closures &amp;#124; Home &amp;#124; [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] &laquo; Visitor pattern with closures | Home | [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Howard Lovatt</title>
		<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32617</link>
		<pubDate>Fri, 14 Mar 2008 21:16:48 +0000</pubDate>
		<guid>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32617</guid>
					<description>In my own pet project, Pattern Enforcing Compiler (PEC):

&lt;blockquote&gt; &lt;a href=&quot;http://pec.dev.java.net/nonav/compile/index.html&quot; rel=&quot;nofollow&quot;&gt; http://pec.dev.java.net/nonav/compile/index.html &lt;/a&gt; &lt;/blockquote&gt;

You can use multiple dispatch instead of visitor:

&lt;blockquote&gt; &lt;a href=&quot;http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#WalkingAnExpressionTree&quot; rel=&quot;nofollow&quot;&gt; http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#WalkingAnExpressionTree &lt;/a&gt; &lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>In my own pet project, Pattern Enforcing Compiler (PEC):</p>
<blockquote><p> <a href="http://pec.dev.java.net/nonav/compile/index.html" rel="nofollow"> <a href='http://pec.dev.java.net/nonav/compile/index.html' rel='nofollow'>http://pec.dev.java.net/nonav/compile/index.html</a> </a> </p></blockquote>
<p>You can use multiple dispatch instead of visitor:</p>
<blockquote><p> <a href="http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#WalkingAnExpressionTree" rel="nofollow"> <a href='http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#WalkingAnExpressionTree' rel='nofollow'>http://pec.dev.java.net/nonav/compile/javadoc/pec/compile/multipledispatch/package-summary.html#WalkingAnExpressionTree</a> </a> </p></blockquote>
]]></content:encoded>
				</item>
	<item>
		<title>by: Mark Mahieu</title>
		<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32552</link>
		<pubDate>Fri, 14 Mar 2008 14:13:36 +0000</pubDate>
		<guid>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32552</guid>
					<description>I'll be curious to see what you come up with as a 'Visitor Builder' - I was planning to write a short blog entry on that subject myself.  The ability to modify local variables and (in BGGA) use non-local returns would make some of my existing uses of the Visitor pattern much simpler...</description>
		<content:encoded><![CDATA[<p>I&#8217;ll be curious to see what you come up with as a &#8216;Visitor Builder&#8217; - I was planning to write a short blog entry on that subject myself.  The ability to modify local variables and (in BGGA) use non-local returns would make some of my existing uses of the Visitor pattern much simpler&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Alex</title>
		<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32535</link>
		<pubDate>Fri, 14 Mar 2008 13:11:45 +0000</pubDate>
		<guid>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32535</guid>
					<description>@Neal - gotcha, I'll give that a shot and you can tell me how I did.  :)

@Peter - yeah, I know.  If you take a look at my older visitor article (linked above), you'll see a full treatment of the navigation issue.</description>
		<content:encoded><![CDATA[<p>@Neal - gotcha, I&#8217;ll give that a shot and you can tell me how I did.  :)</p>
<p>@Peter - yeah, I know.  If you take a look at my older visitor article (linked above), you&#8217;ll see a full treatment of the navigation issue.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Peter Veentjer</title>
		<link>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32534</link>
		<pubDate>Fri, 14 Mar 2008 13:01:11 +0000</pubDate>
		<guid>http://tech.puredanger.com/2008/03/13/visitor-pattern-with-closures/#comment-32534</guid>
					<description>@Alex.
One of the things I do when writing visitors is to make the accept method really stupid:
all implementation just have visitor.visit(this). The traversal should be task of the visitor. If I need reusable traversals, I create visitor guides:

class DepthFirstNodeVisitorGuide implements NodeVisitor{
	private final NodeVisitor guest;

	public DepthFirstNodeVisitorGuide(NodeVisitor guest){
		this.guest = guest;
	}

	public void visit(ConcreteNode node){
		node.accept(guest);
	}

	public void visit(ConcreteNode node){
		for(Node child: node.getChildren()){
			node.accept(this);
		}

		node.accept(guest);
	}
}

If you want to apply it, you can say something like this:

node.accept(new DepthFirstNodeVisitorGuide(new PrintNodeVisitor());

@back on subject.
The last example you gave (with the 'if(v instanceof ConcreteNode)') typically is something you would not see with a visitor. The question is: it is possible to lift on a different dynamic dispatching mechanism other than the polymorphic dispatch, or to use that polymorphic dispatch for closures.

It is a shame that Java has so many features but not something 'simple' as multi-dispatch.</description>
		<content:encoded><![CDATA[<p>@Alex.<br />
One of the things I do when writing visitors is to make the accept method really stupid:<br />
all implementation just have visitor.visit(this). The traversal should be task of the visitor. If I need reusable traversals, I create visitor guides:</p>
<p>class DepthFirstNodeVisitorGuide implements NodeVisitor{<br />
	private final NodeVisitor guest;</p>
<p>	public DepthFirstNodeVisitorGuide(NodeVisitor guest){<br />
		this.guest = guest;<br />
	}</p>
<p>	public void visit(ConcreteNode node){<br />
		node.accept(guest);<br />
	}</p>
<p>	public void visit(ConcreteNode node){<br />
		for(Node child: node.getChildren()){<br />
			node.accept(this);<br />
		}</p>
<p>		node.accept(guest);<br />
	}<br />
}</p>
<p>If you want to apply it, you can say something like this:</p>
<p>node.accept(new DepthFirstNodeVisitorGuide(new PrintNodeVisitor());</p>
<p>@back on subject.<br />
The last example you gave (with the &#8216;if(v instanceof ConcreteNode)&#8217;) typically is something you would not see with a visitor. The question is: it is possible to lift on a different dynamic dispatching mechanism other than the polymorphic dispatch, or to use that polymorphic dispatch for closures.</p>
<p>It is a shame that Java has so many features but not something &#8217;simple&#8217; as multi-dispatch.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
