From: Luke Graham Date: 2005-03-18T10:04:22+09:00 Subject: Re: tree transformation insight required On Thu, 17 Mar 2005 17:27:17 +0900, Simon Strandgaard wrote: > On Wed, 9 Mar 2005 19:00:46 +0900, Luke Graham wrote: > [snip] > > Can anyone suggest a good way to get the c++-producing code out > > of recurse and into some sort of template language, or into functions > > that get passed into simplified recurse? I figured those functions > > would need to return functions (usually themselves) to simulate > > some state changes, ala... > [snip] > > I have had good results with visitor design pattern and interpreter > design pattern. > > For instance have a look at the bottom most class in this file > http://rubyforge.org/cgi-bin/viewcvs.cgi/projects/regexp_engine/source/scanner_nodes.rb?rev=1.22&cvsroot=aeditor&content-type=text/vnd.viewcvs-markup Thats not a million miles from my first cut at an XSLT template. The lightning bolt was when I saw templates could take params.. in other words, they were functions. Everything fell into place then and I saw XSLT for what it really is... a completely average pure-functional programming language designed by committee. Its good in the sense that its templating via XPath, but missing (IMHO) vital things like I/O, built-in higher-order functions and of course terse syntax. My little language shows how trivial the core ideas of XSLT really are, and how it is XPath that does the real heavy lifting. My executive decision for the day is to finish the first version using my big nasty script, because its good enough to get something out there. Version 2 will have better intermediate code because the templating style will suit the problem better, but I will just use XSLT from now on. Despite the ugly language, its hard to write class { (); ~(); int ; }; better in any other style of programming. Has anyone heard of an alternate syntax for XSLT? I used %< ... >% for nesting, %var% for attributes because they were the common case, and %% ... %% for instructions like I/O. Ok, enough non-Ruby talk now :D -- spooq