{"id":847,"date":"2014-05-06T19:22:16","date_gmt":"2014-05-06T19:22:16","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=847"},"modified":"2014-05-06T19:22:16","modified_gmt":"2014-05-06T19:22:16","slug":"lazy-lists-are-late-binding","status":"publish","type":"post","link":"https:\/\/blog.thoughtstorms.info\/?p=847","title":{"rendered":"Lazy Lists Are Late-Binding"},"content":{"rendered":"<p>A thought that struck me in the swimming pool today.<br \/>\nLazy lists are another kind of late-binding.<br \/>\nEveryone hypes lazy lists by saying &#8220;wow! you can even have infinitely long lists!&#8221;<br \/>\nTo which the natural response is, &#8220;So what? The universe is finite and my life and this program are certainly finite, why should I care?&#8221;<br \/>\nBut, instead think about this. &#8220;Infinite lists&#8221; are really &#8220;unbounded lists&#8221; are really &#8220;when you create them, you don&#8217;t know how long you want them to be&#8221; lists.<br \/>\nIt&#8217;s another part of the program, the &#8220;consumer&#8221; of the list, which knows how long you want them to be.<br \/>\nFor example, I&#8217;m currently generating patterns in Clojure + Quil. Here&#8217;s one which is basically formed by filling a grid with a number of tiles.<br \/>\n<img decoding=\"async\" src=\"http:\/\/1.bp.blogspot.com\/-1reSjoHemkU\/U1q6NZlqgcI\/AAAAAAAAAvY\/ALlc7pCcRCg\/s1600\/p18.png\" alt=\"Patterning\" \/><br \/>\nThe important thing here is that, although I know I want a repeated pattern of different tiles, I don&#8217;t need to know how many of these tiles in total I&#8217;m actually going to need to fill my grid, so I just create an infinite list, using<br \/>\n(cycle [tile1 tile2 tile3 tile4])<br \/>\nThen I have a function which zips the list of tiles with a list of positions to be filled. The list of tiles is infinite, but the list of positions on the grid isn&#8217;t, so the zipping ends up with a finite grid of tiles.<br \/>\nIn a sense, this is yet another example of &#8220;late-binding&#8221; (ie. leaving decisions as late as possible). It allows the names of data-structures to stand for things (data-structure) whose shape and extent is determined much later.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A thought that struck me in the swimming pool today. Lazy lists are another kind of late-binding. Everyone hypes lazy lists by saying &#8220;wow! you can even have infinitely long lists!&#8221; To which the natural response is, &#8220;So what? The universe is finite and my life and this program are certainly finite, why should I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[67,242,243],"class_list":["post-847","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-clojurescript","tag-late-binding","tag-laziness"],"_links":{"self":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/847","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=847"}],"version-history":[{"count":0,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/847\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}