{"id":24,"date":"2006-02-19T08:36:07","date_gmt":"2006-02-19T16:36:07","guid":{"rendered":"http:\/\/evanlenz.net\/blog\/?p=24"},"modified":"2006-02-20T09:33:13","modified_gmt":"2006-02-20T17:33:13","slug":"contemplating-s-expressions-in-bed","status":"publish","type":"post","link":"https:\/\/evanlenz.net\/blog\/2006\/02\/19\/contemplating-s-expressions-in-bed\/","title":{"rendered":"XSLT template rules vs. Lisp macros"},"content":{"rendered":"<p>In bed this morning, I was contemplating all I learned about Lisp last night. XSLT&#8217;s most obvious analog to Lisp macros is its ability to generate stylesheet code, since XSLT is in XML syntax.<\/p>\n<p>But if data is really code, then XSLT template rules are also like macro definitions. An element in the source document is processed and thereby expanded, causing the code in the body of the corresponding template rule to be executed.<\/p>\n<p>At one level, template rules seem more powerful than Lisp macros. A macro is defined by a <em>name<\/em> and resolved via name-lookup, whereas a template rule is defined by a <em>pattern<\/em> and resolved via pattern-matching. I don&#8217;t think I&#8217;ve encountered this level of indirection yet in my two days of learning Lisp. I&#8217;m curious what the best analog to this pattern-based function resolution is in Lisp. Maybe the best analog is to be found in particular Lisp functions, such as remove-if-not. Perhaps XSLT&#8217;s core processing model is like just another Lisp function.<\/p>\n<p>An obvious difference is that Lisp macros are expanded recursively, whereas template rules are just applied once. I&#8217;ve wanted a way to apply them recursively sometimes (well, <em>certain<\/em> template rules in my stylesheet if not all of them). This isn&#8217;t built in to XSLT. Either you have to store a temporary result in a variable and then process the results again, or you have to define a pipeline process outside of XSLT to invoke the XSLT processor. I&#8217;ve contemplated how a more automatic recursive application of template rules might look or might be built into an XSLT-like language.<\/p>\n<p>Anytime you learn something new, you&#8217;re going to compare it to what you already know. So far, it seems like having an XSLT background is going to be helpful in my learning of Lisp.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In bed this morning, I was contemplating all I learned about Lisp last night. XSLT&#8217;s most obvious analog to Lisp macros is its ability to generate stylesheet code, since XSLT is in XML syntax. But if data is really code, then XSLT template rules are also like macro definitions. An element in the source document [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/posts\/24"}],"collection":[{"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":0,"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"wp:attachment":[{"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evanlenz.net\/blog\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}