{"id":403,"date":"2007-11-28T05:00:00","date_gmt":"2007-11-28T05:00:00","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=403"},"modified":"2007-11-28T05:00:00","modified_gmt":"2007-11-28T05:00:00","slug":"403","status":"publish","type":"post","link":"https:\/\/blog.thoughtstorms.info\/?p=403","title":{"rendered":""},"content":{"rendered":"<p>What&#8217;s this?<\/p>\n<ul>\n<li>1<\/li>\n<li>2\n<ul>\n<li>21\n<ul>\n<li>211<\/li>\n<\/ul>\n<\/li>\n<li>22<\/li>\n<\/ul>\n<\/li>\n<li>3<\/li>\n<li>4\n<ul>\n<li>41<\/li>\n<li>42<\/li>\n<li>43\n<ul>\n<li>431\n<ul>\n<li>4311<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>5<\/li>\n<\/ul>\n<p>An HTML list that came out of GeekWeaver, when I called this recursive function :<\/p>\n<pre><br \/><br \/>::rec<br \/>  .<ul><br \/>    :for x,, #__<br \/>      .<li><br \/>        ${x\/=}<br \/>        :hasChild x<br \/>          :rec ++ #x__<br \/><\/pre>\n<p>on a chunk of OPML.<\/p>\n<p>That&#8217;s pretty much how it&#8217;s going to look, folks. <\/p>\n<p>::rec defines the recursive block (or function)<\/p>\n<p>.<\/p>\n<ul> creates the UL tag<\/p>\n<p>:for x,, #__ <\/p>\n<p>is creating a loop through all the anonymous (unlabelled) children of the tree which is being passed to the call. (This list is represented by the symbol __) <\/p>\n<p>Note that I&#8217;m trying to keep GeekWeaver as functional as possible so there&#8217;s no real &#8220;assignment&#8221;. x is scoped so that it only exists inside the block of the for-loop, it&#8217;s bound once before the block is evaluated, but can&#8217;t be updated after that.<\/p>\n<p>${x\/=}<\/p>\n<p>This is the new way of accessing variables. x is actually bound to a sub-tree (Almost everything in GeekWeaver is a sub-tree, except a couple of weird cases like __ which is a list.) <\/p>\n<p>Although a simple $x still works if you want the whole of a tree flattened into a string, ${} expressions give you a way to pull data from a single path in the tree. In this case we&#8217;re just getting the text content of the root node of x. <\/p>\n<p>But it&#8217;s also possible to write stuff like this : ${company\/employees\/__3\/name} which means from the symbol &#8220;company&#8221; get the labelled child &#8220;employees&#8221; from which get the non-labelled 3rd child, from which get the child labelled &#8220;name&#8221;.<\/p>\n<p>:hasChild, like :for, is a build-in function. If the tree in x has any children, it evaluates the body of the :hasChild tree. If not, it returns nothing. This tests for our &#8220;base-case&#8221; when we&#8217;ve hit a leaf of the tree we&#8217;re recursing through.<\/p>\n<p>The final line :<\/p>\n<p>:rec ++ #x__<\/p>\n<p>is the one which I&#8217;ve been struggling with for the last three months, ever since I started trying to figure out how to support recursion. I&#8217;m still not 100% happy with the solution I&#8217;ve come up with, but it&#8217;s getting there. <\/p>\n<p>:rec is calling the recursive block again. And obviously I need to pass the children of x as arguments. However the way the function is written, it is working on the anonymous children (inside the default variable __)<\/p>\n<p>How am I going to get the children of x into the __ variable inside the next call of :rec? That&#8217;s what ++ does. Not sure what I&#8217;m going to call this, I may call it a &#8220;pivot&#8221; although that may confuse as much as help. It captures something of the idea that I need to swing the anonymous children of x (#x__) around so that they can go into the next call of :rec <em>as though they were children of the calling node<\/em><\/p>\n<p>Like I say, don&#8217;t know if I like this name or the ++ symbol being used for it. So consider both as provisional for now.<\/p>\n<p>OK, I&#8217;m too tired to make the build with this stuff working tonight. I&#8217;ll try to get a build together in the next couple of days, but meanwhile, if this looks interesting to you and you can&#8217;t contain yourself, send me an email (interstarATgmail.com), say hello and I&#8217;ll see what I can do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s this? 1 2 21 211 22 3 4 41 42 43 431 4311 5 An HTML list that came out of GeekWeaver, when I called this recursive function : ::rec . :for x,, #__ . ${x\/=} :hasChild x :rec ++ #x__ on a chunk of OPML. That&#8217;s pretty much how it&#8217;s going to look, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[173],"class_list":["post-403","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-geekweaver"],"_links":{"self":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=403"}],"version-history":[{"count":0,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/403\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}