<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[MOHAMMED JAMAL ALRUJAYI]]></title><description><![CDATA[Running Cycls]]></description><link>https://aljamal.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!Nl8s!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2feb282a-3db9-45d9-8ed9-03fb3a7ae3b9_900x900.png</url><title>MOHAMMED JAMAL ALRUJAYI</title><link>https://aljamal.substack.com</link></image><generator>Substack</generator><lastBuildDate>Tue, 11 Aug 2026 04:03:04 GMT</lastBuildDate><atom:link href="https://aljamal.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Mohammed Jamal]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[aljamal@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[aljamal@substack.com]]></itunes:email><itunes:name><![CDATA[Mohammed Alrujayi]]></itunes:name></itunes:owner><itunes:author><![CDATA[Mohammed Alrujayi]]></itunes:author><googleplay:owner><![CDATA[aljamal@substack.com]]></googleplay:owner><googleplay:email><![CDATA[aljamal@substack.com]]></googleplay:email><googleplay:author><![CDATA[Mohammed Alrujayi]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Golfing APL/K in 90 Lines of Python]]></title><description><![CDATA[Lisp + APL = K]]></description><link>https://aljamal.substack.com/p/golfing-aplk-in-90-lines-of-python</link><guid isPermaLink="false">https://aljamal.substack.com/p/golfing-aplk-in-90-lines-of-python</guid><dc:creator><![CDATA[Mohammed Alrujayi]]></dc:creator><pubDate>Fri, 16 Jan 2026 19:32:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!tpX2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tpX2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tpX2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 424w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 848w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 1272w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tpX2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic" width="1456" height="1000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1000,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:643445,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tpX2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 424w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 848w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 1272w, https://substackcdn.com/image/fetch/$s_!tpX2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e35f49d-a7b1-4a5b-8b38-38319ed492cb_1968x1352.heic 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Egyptian hieroglyphs, an early visual notation</figcaption></figure></div><p>In my previous post on <a href="https://aljamal.substack.com/p/homoiconic-python">Homoiconic Python</a>, I explored McCarthy&#8217;s Lisp, a language where code and data are the same thing. But there&#8217;s another path to expressive power, one that emerged in parallel.</p><p>At the <a href="https://en.wikipedia.org/wiki/Dartmouth_workshop">1956 Dartmouth conference</a>, John McCarthy encountered Newell and Simon&#8217;s list-processing language IPL. He liked the idea of lists but hated the language itself, so he spent the next two years building <a href="http://jmc.stanford.edu/articles/lisp/lisp.pdf">Lisp</a> at MIT. That same year, <a href="https://en.wikipedia.org/wiki/Kenneth_E._Iverson">Kenneth Iverson</a> was teaching mathematics at Harvard and growing frustrated with the inadequacy of conventional notation for expressing algorithms. He began inventing his own, publishing it in 1962 as <em><strong>A Programming Language</strong></em>, the book that gave APL its name.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aljamal.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading MOHAMMED JAMAL ALRUJAYI! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>APL looked like nothing else. Iverson designed a new alphabet, like Egyptian hieroglyphics, each symbol a complete idea:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cslb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cslb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cslb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg" width="1390" height="1264" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1264,&quot;width&quot;:1390,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:188644,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bbf1539-2864-483c-8551-97abf069be25_1390x1264.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Cslb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Cslb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1e943ea-e7f5-4e9d-b59c-db90995baa98_1390x1264.jpeg 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Modern APL glyphs</figcaption></figure></div><p>APL is <a href="https://www.youtube.com/watch?v=a9xAKttWgP4&amp;t=2s">very expressive</a>. Here is the complete implementation of <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Conway's Game of Life</a> in APL:</p><pre><code>      life &#8592; {&#8835;1 &#9077; &#8744;.&#8743; 3 4 = +/ +&#9023; &#175;1 0 1 &#8728;.&#8854; &#175;1 0 1 &#9021;&#168; &#8834;&#9077;}</code></pre><p>And just like Lisp, APL had one data structure: <strong>the array. </strong>Lisp had the list.</p><p>This shared minimalism is the first hint of a deeper, ancestral bond.</p><p>Lisp was born at MIT; APL at Harvard.<strong> </strong>Lisp processes lists; APL processes matrices. Lisp inherits from Church&#8217;s lambda calculus; APL from Curry&#8217;s combinators. Lisp was designed for machines to do symbolic reasoning; APL was designed for humans to communicate mathematical ideas. One prioritizes semantic elegance, the other syntactic density.</p><div class="pullquote"><p>APL and LISP are very similar languages&#8212;both manipulate a complex data structure and the functional structure of the languages has been ideally chosen for convenient manipulation of these structures. Proposals have been made to combine them by embedding one within the other.</p></div><p>In 1979, <a href="https://dl.acm.org/doi/10.1145/800136.804474">Alan Perlis</a> (the first recipient of the Turing Award) chaired a <a href="https://dl.acm.org/doi/10.1145/800136.804474#:~:text=APL%20and%20LISP%20are%20very,embedding%20one%20within%20the%20other.">panel</a> asking:<strong> </strong><em><strong>&#8221;</strong></em><strong>APL and LISP&#8212;should they be combined, and if so how</strong><em><strong>?&#8221;</strong></em> The panel debated embedding one within the other, or generalizing both into something superior. No conclusion was reached. That same year, Iverson received his own Turing Award and delivered his famous lecture: <em><strong><a href="https://www.eecg.utoronto.ca/~jzhu/csc326/readings/iverson.pdf">Notation as a Tool of Thought</a></strong></em>.</p><h2><strong>Iverson&#8217;s Ghosts</strong></h2><p>You&#8217;ve probably used Iverson&#8217;s ideas without knowing it. John Baker calls NumPy an <a href="https://analyzethedatanotthedrivel.org/2018/03/31/numpy-another-iverson-ghost/">&#8221;Iverson ghost&#8221;</a>, APL&#8217;s array programming reborn in Python&#8217;s syntax. Broadcasting, vectorization, reduction along axes-these aren&#8217;t NumPy inventions. They&#8217;re Iverson&#8217;s ideas from the 1960s, wrapped in <code>`np.`</code> prefixes and spelled out in English.</p><p>PyTorch, TensorFlow, JAX-the entire deep learning stack speaks Iverson&#8217;s dialect with extra syllables. <code>`np.arange(10)`</code> is <code>`!10`</code>. <code>`np.cumsum(x)`</code> is <code>`+\x`</code>. <code>`x[::-1]`</code> is <code>`|x`</code>. Same concepts, more typing.</p><h2><strong>The Prophecy Fulfilled</strong></h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Kc9U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Kc9U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 424w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 848w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 1272w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Kc9U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic" width="456" height="337.3021978021978" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1077,&quot;width&quot;:1456,&quot;resizeWidth&quot;:456,&quot;bytes&quot;:435045,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Kc9U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 424w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 848w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 1272w, https://substackcdn.com/image/fetch/$s_!Kc9U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bd4a8ca-8abd-41cb-922e-1e0b9459d273_1500x1110.heic 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Ken Iverson &amp; Arthur Whitney at APL91</figcaption></figure></div><p><a href="https://aplwiki.com/wiki/Arthur_Whitney">Arthur Whitney</a>, Iverson&#8217;s prot&#233;g&#233;,<em> </em>saw both languages clearly. On <a href="https://web.archive.org/web/20170314100110/http://kparc.com/">kparc.com</a> (his personal website) he listed K&#8217;s lineage simply as &#8220;lisp and apl,&#8221; linking to Iverson&#8217;s Turing paper and Perlis&#8217;s <a href="https://www.jsoftware.com/papers/perlis77.htm">lyrical programming</a>. In a <a href="https://queue.acm.org/detail.cfm?id=1531242">2009 interview</a>, he explained: <em><strong>&#8221;I much preferred implementing and coding in LISP, but once I was dealing with big data sets... APL just seemed to have the better vocabulary.&#8221;</strong></em> He understood their complementary strengths: <em><strong>&#8221;What I liked was the original LISP, which had car, cdr, cons, and cond, but that was too little. Common LISP was way too big, but a stripped-down version of APL was in the middle with about 50 operations.&#8221;</strong></em></p><p>Whitney first encountered APL at age 11, when Iverson (a friend of his father&#8217;s) demonstrated interactive programming on a terminal in 1969. But it wasn&#8217;t until 1980, working alongside Iverson at I.P. Sharp in Toronto, that he began using it seriously. Through the &#8216;80s he explored broadly, implementing his own object-oriented languages, various Lisps, and Prolog. In 1988 he joined Morgan Stanley and built trading systems using his own APL dialect, which became A+.</p><h3><strong>Incunabulum</strong></h3><p>In 1989, Whitney visited Iverson at Kiln Farm. Iverson and <a href="https://en.wikipedia.org/wiki/Roger_Hui">Roger Hui</a> were working on a new APL dialect-one that would use ASCII instead of special glyphs. Over one afternoon, Whitney wrote the now famous <em><strong><a href="https://code.jsoftware.com/wiki/Essays/Incunabulum">incunabulum</a></strong></em>. A one page interpreter in C.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pAfA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pAfA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 424w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 848w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pAfA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg" width="724" height="1162.8087535680304" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1688,&quot;width&quot;:1051,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:413059,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe90fcc9e-0b8e-49cb-937e-a68a004f2ae7_1542x1688.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pAfA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 424w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 848w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!pAfA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6517be8-c996-4de6-b99e-42d4f5707dba_1051x1688.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Arthur's one-page interpreter (an early version of J), <a href="https://ktye.github.io/zoo/index.html#j0">try it on your browser</a></figcaption></figure></div><p>That&#8217;s Arthur&#8217;s style: C that looks like APL. Macros turn C into a higher-order language; by the time he writes the interpreter, he&#8217;s writing APL in C. It looks alien at first glance, then you see it. This is <a href="https://en.wikipedia.org/wiki/Code_golf">code golfing</a> at its earliest (popular among APL hackers long before Perl coined the term).</p><p>Roger Hui studied that page for a week, then wrote the first line of what would become <a href="https://en.wikipedia.org/wiki/J_(programming_language)">J</a>. J shipped in 1990, the first ASCII APL. But Whitney wasn&#8217;t done.</p><h3><strong>K</strong></h3><p>In 1992, Whitney created K. Where J modernized APL&#8217;s syntax, K transformed its semantics. On <a href="https://web.archive.org/web/20170713190011/http://kparc.com/lisp.txt">kparc.com</a>, he laid out exactly what K inherited from each parent:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7HVj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7HVj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 424w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 848w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 1272w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7HVj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic" width="640" height="904.8275862068965" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1476,&quot;width&quot;:1044,&quot;resizeWidth&quot;:640,&quot;bytes&quot;:95120,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7HVj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 424w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 848w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 1272w, https://substackcdn.com/image/fetch/$s_!7HVj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d671150-a2a0-4fd4-b615-388aacbfe674_1044x1476.heic 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The parallel history of Lisp &amp; APL/K according to Arthur Whitney</figcaption></figure></div><p>The parallels are striking. Both functional. Both dynamic. Both built on atoms and lists with maps between them. Both with REPLs and lexical scope. The syntax differs (s-expressions versus m-expressions) but the bones are the same.</p><div class="pullquote"><p><em><strong>K marked a major departure from APL tradition and towards LISP influence, since it discarded APL&#8217;s multidimensional array model in favor of nested lists.</strong></em></p></div><p>The Lisp features crept in gradually. Lambda and conditionals appeared in the 1970s. Higher-order operators-map and reduce-arrived in 1979, the same year Perlis posed his question. ASCII came with J in 1989. But the decisive break was 1992: K abandoned APL&#8217;s multidimensional arrays for nested lists-Lisp&#8217;s data structure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vyBm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vyBm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 424w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 848w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 1272w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vyBm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic" width="658" height="664.4061196105703" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1452,&quot;width&quot;:1438,&quot;resizeWidth&quot;:658,&quot;bytes&quot;:208434,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vyBm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 424w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 848w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 1272w, https://substackcdn.com/image/fetch/$s_!vyBm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e27253a-1335-4917-87b0-bd84aa599a0f_1438x1452.heic 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The enire documentation of modern k</figcaption></figure></div><p>APL &amp; Lisp, after four decades of parallel evolution, finally merged as k.</p><h2><strong>K Verses</strong></h2><p>This is what K looks like (using the 90 lines python implemntation from next section). Factorial:</p><pre><code><code> */1+!5

120</code></code></pre><p>Average:</p><pre><code><code> (+/x)%#x:!100

49.5</code></code></pre><p>Primes under 50:</p><pre><code><code> &amp;2=+/0=(a)mod/a:1+!50

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] &#129327;</code></code></pre><p>Golden ratio via continued fraction:</p><pre><code><code> 0{1+1%x}/1

1.618033988749895</code></code></pre><p>Fibonacci:</p><pre><code><code> 5{|+\x}\1,2

[[1, 2], [3, 1], [4, 3], [7, 4], [11, 7], [18, 11]]</code></code></pre><p>Pi via Madhava series:</p><pre><code><code> 4*+/(-*\-_a%a:1+!n)*1%1+2*!n:1000000

3.1415916535897743</code></code></pre><p>Euler&#8217;s number:</p><pre><code><code> */x*1+1%#x:_x%x:1+!1000000

2.7182804690959363</code></code></pre><p>Square root of 2 via Newton:</p><pre><code><code> 1+100{1%2+x}/1

1.4142135623730951</code></code></pre><h2><strong>A Python Implementation</strong></h2><p>How do you build K in Python?</p><p>The data structure is already there, Python lists can represent Lisp lists (as I showed in my previous post). The symbols? K already uses ASCII. What&#8217;s missing is what makes APL special: everything is vectorized. We need <a href="https://aplwiki.com/wiki/Scalar_extension">scalar extension</a>. Then parser/eval, this is where we lay the syntactic sugar, the notation if you will, of APL on top of Lisp. Lisp is semantics, APL is syntax.</p><h3>Scalar Extension</h3><p>Enter <strong>monad</strong> and <strong>dyad</strong>. Two higher-order functions that vectorize <em>*<strong>any*</strong></em> Python function:</p><pre><code><code>atom = lambda x: isinstance(x, (int, float, str))
monad = lambda f: lambda x: f(x) if atom(x) else list(map(monad(f), x))
dyad = lambda f: (lambda x, y: f(x, y) if atom(x) and atom(y)
  else list(map(lambda yi: dyad(f)(x, yi), y)) if atom(x)
  else list(map(lambda xi: dyad(f)(xi, y), x)) if atom(y)
  else list(map(lambda xi, yi: dyad(f)(xi, yi), x, y)))</code></code></pre><p><strong>Monad</strong> lifts a unary (one argument, i.e. f(x)) function. <strong>Dyad</strong><code> </code>lifts a binary (two arguments, i.e. f(x,y)) one. They recurse into structure until they find atoms, then apply. This is scalar extension, the heart of array programming.</p><p>Watch what happens:</p><pre><code><code>&gt;&gt;&gt; import math

&gt;&gt;&gt; sqrt = monad(math.sqrt)

&gt;&gt;&gt; sqrt(4)

2.0

&gt;&gt;&gt; sqrt([4, 9, 16])

[2.0, 3.0, 4.0]

&gt;&gt;&gt; sqrt([[4, 9], [16, 25]])

[[2.0, 3.0], [4.0, 5.0]]

&gt;&gt;&gt; add = dyad(lambda x, y: x + y)

&gt;&gt;&gt; add(1, 2)

3

&gt;&gt;&gt; add(10, [1, 2, 3])

[11, 12, 13]

&gt;&gt;&gt; add([1, 2], [10, 20])

[11, 22]</code></code></pre><p>Any function. Any depth. No loops. No NumPy. Just two higher-order functions.</p><p><strong>dyad</strong> function works exactly like this:</p><ul><li><p>atom + atom &#8594; apply directly</p></li><li><p>atom + list &#8594; extend the atom (scalar extension)</p></li><li><p>list + atom &#8594; extend the atom (scalar extension)</p></li><li><p>list + list &#8594; pairwise</p></li></ul><p><strong>monad</strong> function makes functions pervasive, it penetrates into nested structures recursively.</p><p>These two functions are what inspired me to build the whole thing.</p><h3>90 Lines Later</h3><p>Armed with scalar extension and a feel for K&#8217;s semantics, I wanted to see how far terseness could go. I wanted to implement the whole thing in under 100 lines of Python, honoring the tradition of my predecessors. Here it is:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kFMO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kFMO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 424w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 848w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 1272w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kFMO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic" width="728" height="202.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:405,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:202915,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kFMO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 424w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 848w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 1272w, https://substackcdn.com/image/fetch/$s_!kFMO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c465fe6-86ac-40d0-9a47-be008386067f_2428x676.heic 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">K functions</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rhox!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rhox!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 424w, https://substackcdn.com/image/fetch/$s_!rhox!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 848w, https://substackcdn.com/image/fetch/$s_!rhox!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 1272w, https://substackcdn.com/image/fetch/$s_!rhox!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rhox!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic" width="608" height="364.54945054945057" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:873,&quot;width&quot;:1456,&quot;resizeWidth&quot;:608,&quot;bytes&quot;:171599,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rhox!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 424w, https://substackcdn.com/image/fetch/$s_!rhox!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 848w, https://substackcdn.com/image/fetch/$s_!rhox!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 1272w, https://substackcdn.com/image/fetch/$s_!rhox!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29599d60-0483-4034-a702-8a1764236b8f_1534x920.heic 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Apply &amp; Eval</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u9Cd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u9Cd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 424w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 848w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 1272w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u9Cd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic" width="617" height="291.1256868131868" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:687,&quot;width&quot;:1456,&quot;resizeWidth&quot;:617,&quot;bytes&quot;:96199,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/heic&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aljamal.substack.com/i/184711345?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u9Cd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 424w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 848w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 1272w, https://substackcdn.com/image/fetch/$s_!u9Cd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff045ac74-a29a-4e90-aa5e-9efe34f03eb6_1908x900.heic 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Parser and REPL</figcaption></figure></div><p>Lisp: code is data. Empahsis on semantics.</p><p>APL: notation is thought. Empahsis on syntax.</p><p>K: both.</p><p>Less is more.</p><p>For more details, check out <a href="https://github.com/aburjg/k.py">k.py on GitHub</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aljamal.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading MOHAMMED JAMAL ALRUJAYI! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Homoiconic Python]]></title><description><![CDATA[McCarthy's Lisp in Python lists]]></description><link>https://aljamal.substack.com/p/homoiconic-python</link><guid isPermaLink="false">https://aljamal.substack.com/p/homoiconic-python</guid><dc:creator><![CDATA[Mohammed Alrujayi]]></dc:creator><pubDate>Sun, 12 May 2024 15:57:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!qUlh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qUlh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qUlh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 424w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 848w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qUlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png" width="326" height="315.8914728682171" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1000,&quot;width&quot;:1032,&quot;resizeWidth&quot;:326,&quot;bytes&quot;:436178,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qUlh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 424w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 848w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 1272w, https://substackcdn.com/image/fetch/$s_!qUlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbee1c0c5-488b-4fe9-a6ca-ced469e022dc_1032x1000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The idea of a programming language being able to implement itself is fascinating. It stirs an intense feeling of curiosity: "What would that even look like?" Since its inception in the early '60s, <strong>Lisp</strong> has managed to do exactly that.</p><p><a href="https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist)">John McCarthy</a>, In the early '60s, unlocked a collection of remarkable ideas that work really well together and continue to be relevant decades later. First through the <a href="http://www-formal.stanford.edu/jmc/recursive.pdf">Lisp paper</a>, and shortly thereafter with the <a href="https://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf">Lisp 1.5 manual</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aljamal.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading MOHAMMED JAMAL! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u1vf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u1vf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 424w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 848w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 1272w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u1vf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp" width="296" height="276.33948339483396" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:506,&quot;width&quot;:542,&quot;resizeWidth&quot;:296,&quot;bytes&quot;:36280,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u1vf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 424w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 848w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 1272w, https://substackcdn.com/image/fetch/$s_!u1vf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac5ae3ca-7054-43fd-9cdf-2c396be4f2c0_542x506.webp 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">John McCarthy</figcaption></figure></div><p>One such idea is <strong>homoiconicity</strong>, a trait where code and data are interchangeable. Typically, we think of code as a sequence of operations acting upon data. This understanding shapes our view of most programming languages today. However, Lisp breaks this mold by treating both code and data as the same&#8212;what's famously known as its <a href="https://en.wikipedia.org/wiki/Homoiconicity#:~:text=In%20computer%20programming%2C%20homoiconicity%20(from,as%20data%20using%20the%20language.">homoiconic</a> nature. This distinct characteristic effectively blurs the lines between the operator (code) and the operated (data).</p><p>This unification of code and data in Lisp is profound, it allows a level of expression where the language can be naturally expressed in itself.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r-LN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r-LN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 424w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 848w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r-LN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png" width="1456" height="759" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:759,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:235648,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r-LN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 424w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 848w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!r-LN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b0bdd68-04bf-4246-b3df-b0980d664c17_2222x1158.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Lisp in Lisp</figcaption></figure></div><p>This tiny card is the entire programming language of Lisp! A programming language written in itself. Here is famous quote from <a href="https://en.wikipedia.org/wiki/Alan_Kay">Alan Kay</a> about this piece of coding history:</p><div class="pullquote"><p>that was the big revelation to me &#8230; when I finally understood that the half page of code on the bottom of page 13 of the Lisp 1.5 manual was Lisp in itself. These were "Maxwell's Equations of Software!" This is the whole world of programming in a few lines that I can put my hand over.</p></div><p>Okay, but what sort of magic did Mr. Kay see in this artifact that led him to call it the "Maxwell's Equations of Software"? How was the entire world of programming encapsulated in just a few lines of code?</p><p>One fun way to answer that, of course, is by applying the principle that: "<strong>In order to understand something, you need to code it</strong>".</p><p>And to keep this spiritual implementation of the original Lisp fun and fresh, I decided to pick Python as the tool of choice. Most programmers are either not familiar or not comfortable with Lisp's syntax (<a href="https://xkcd.com/297/">too many parentheses</a>), but probably quite familiar with Python's syntax. My idea is to rewrite the "Lisp in Lisp" code in Python and try to maintain as much of the spirit of the old code as possible.</p><h2>Strange yet familiar</h2><p>Lisp originally, and quite brilliantly, came with two <strong>syntactical</strong> flavors. A code flavor named <strong>M-expression</strong> (short for meta) and a data flavor named <strong>S-expression</strong> (short for symbolic). They're <strong>semantically</strong> equivalent.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0jaJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0jaJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 424w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 848w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 1272w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0jaJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png" width="626" height="179.2870879120879" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:417,&quot;width&quot;:1456,&quot;resizeWidth&quot;:626,&quot;bytes&quot;:176726,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0jaJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 424w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 848w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 1272w, https://substackcdn.com/image/fetch/$s_!0jaJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F405c58a5-58d4-40d2-97e8-4d6b297dd561_2080x596.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">M-expressions side by side to their S-expressions equivalent</figcaption></figure></div><div><hr></div><p>The "Lisp in Lisp" code presented earlier is written as an M-expression (code flavor) and implements an S-expression Lisp (data flavor).</p><p>One little trick to get us going is by translating Lisp M-expressions into Python code constructs, such as function calls and conditional statements. Additionally, we can represent Lisp S-expressions using Python lists. Lisp is short for "List Processing" because it only uses one data structure: the list. Therefore, it makes perfect sense to use Python lists to emulate Lisp S-expressions. Below, I present our mini dictionary that would act as our rosetta stone: </p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KXIu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KXIu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 424w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 848w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 1272w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KXIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png" width="496" height="101.85714285714286" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:299,&quot;width&quot;:1456,&quot;resizeWidth&quot;:496,&quot;bytes&quot;:70594,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KXIu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 424w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 848w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 1272w, https://substackcdn.com/image/fetch/$s_!KXIu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F968c725c-dec5-449e-af08-c5ec69fe8f9f_1900x390.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div><hr></div><p>These are four ways of expressing one thing. They're all semantically<strong> </strong>equivalent.</p><p>An additional advantage of this mapping approach is that it eliminates the need to implement a parser for our language. This simplifies our code base and allows us to stay true to the original spirit of Lisp without getting distracted by string manipulations.</p><h2>First iteration</h2><p>With this context and motivation in place, we can move on to the actual implementation. Lisp requires a set of basic functions to be implemented outside of its scope, they're mostly about the basic building blocks of lists.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OHgG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OHgG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 424w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 848w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 1272w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OHgG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png" width="1456" height="443" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:443,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:141182,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OHgG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 424w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 848w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 1272w, https://substackcdn.com/image/fetch/$s_!OHgG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e85e14c-0eb9-45ce-809a-3df68ae4c11a_2682x816.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Python list primitives to act like Lisp</figcaption></figure></div><ul><li><p>Equivalence</p><ul><li><p><strong>atom(x)</strong>: is x a list?</p></li><li><p><strong>eq(x,y)</strong>: is x equal y?</p></li></ul></li><li><p>Cutting</p><ul><li><p><strong>car(x)</strong>: first element of the list</p></li><li><p><strong>cdr(x)</strong>: the rest of the list</p></li></ul></li><li><p>Stitching</p><ul><li><p><strong>cons(x,y)</strong>: append an atom to a list</p></li><li><p><strong>append(x,y)</strong>: append two lists together</p></li></ul></li></ul><div><hr></div><p>Ignoring a few recursive primitives, and with a little help from <strong><a href="https://llama.meta.com/llama3/">Llama3-70b</a> </strong>(<a href="https://groq.com/">on Groq</a>), we can quickly get a working interpreter for a subset of the "Lisp in Lisp" code:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ycXF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ycXF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 424w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 848w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 1272w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ycXF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png" width="1456" height="1169" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1169,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:312032,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ycXF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 424w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 848w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 1272w, https://substackcdn.com/image/fetch/$s_!ycXF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ae0243d-7e73-421a-960a-f50b6e9ac123_1958x1572.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">A working version of the Lisp in Lisp <strong>M-expression</strong> translated to Python</figcaption></figure></div><p>Here are a few examples you can play with:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1uDR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1uDR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 424w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 848w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 1272w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1uDR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png" width="1456" height="1496" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1496,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:220649,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1uDR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 424w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 848w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 1272w, https://substackcdn.com/image/fetch/$s_!1uDR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbce346-7368-48d8-85dc-37b42429ca20_1472x1512.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Python lists acting as <strong>S-expressions</strong></figcaption></figure></div><div><hr></div><p>Full code available on <a href="https://gist.github.com/aburjg/1dffba5516095050089f6ea293cb782b#first">github gists</a></p><h2>Second iteration</h2><p>Our first iteration is nearly complete, except for one crucial feature: <a href="https://en.wikipedia.org/wiki/Anonymous_function">lambdas</a>. Lambdas are anonymous functions that serve as the primary method for defining and calling functions in Lisp. Without lambdas in Lisp, we cannot implement recursion, and without recursion, our Lisp would not be <a href="https://en.wikipedia.org/wiki/Church&#8211;Turing_thesis#:~:text=The%20thesis%20can%20be%20stated,represented%20as%20a%20Turing%20Machine%22.">Turing complete</a> (the minimum threshold to compute all which can be computed). </p><p>To incorporate lambdas, we need to add a few functions we previously overlooked, specifically two primitives: <strong>assoc(x,y)</strong> and <strong>pairlis(x,y)</strong>. <strong>assoc(x,y)</strong> is a key/value dictionary style lookup but implemented with lists instead (associative lists). parlis is just the <strong>zip(x,y)</strong> in Python (ziping two lists together).</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5JMS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5JMS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 424w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 848w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 1272w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5JMS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png" width="594" height="361.0508241758242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:885,&quot;width&quot;:1456,&quot;resizeWidth&quot;:594,&quot;bytes&quot;:484840,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5JMS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 424w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 848w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 1272w, https://substackcdn.com/image/fetch/$s_!5JMS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab54c10f-a5d7-4605-8665-f4f65cb6927f_1694x1030.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><strong>pairlis</strong> and <strong>assoc</strong> as they first appeared in the Lisp 1.5 manual</figcaption></figure></div><div><hr></div><p>A literal translation in Python would be:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w7Ep!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w7Ep!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 424w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 848w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 1272w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w7Ep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png" width="1456" height="671" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:671,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:234791,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w7Ep!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 424w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 848w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 1272w, https://substackcdn.com/image/fetch/$s_!w7Ep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F507f7502-872f-4cc8-a950-e95d714c8caf_2576x1188.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">A literal (<strong>recursive</strong>) Lisp to Python translation of <strong>assoc</strong> and <strong>pairlis</strong></figcaption></figure></div><p>The original Lisp had to resort to <strong>recursion</strong> (function calling itself) even for simple, linear scans, since it had no <a href="https://en.wikipedia.org/wiki/For_loop">loops</a>. However, <strong>assoc</strong> and <strong>pairlis</strong> can be elegantly translated to Python using <strong>list comprehensions</strong>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FrZR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FrZR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 424w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 848w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 1272w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FrZR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png" width="1456" height="176" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:176,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64335,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FrZR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 424w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 848w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 1272w, https://substackcdn.com/image/fetch/$s_!FrZR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1e8befb-3b17-47c9-940d-2c7310ad7016_2184x264.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Python supports both <strong>loops</strong> and <strong>recursion</strong></figcaption></figure></div><p>and if you hadn't noticed already I actually cheated a bit in the COND case as this in the original lisp was a <strong>evcon</strong> which was also translated into a loop. The same trick will be done again with <strong>evlis</strong> for the LAMBDA case.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jF0K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jF0K!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 424w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 848w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 1272w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jF0K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png" width="642" height="201.06593406593407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:456,&quot;width&quot;:1456,&quot;resizeWidth&quot;:642,&quot;bytes&quot;:102839,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jF0K!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 424w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 848w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 1272w, https://substackcdn.com/image/fetch/$s_!jF0K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ac6b137-0f3b-417b-abb3-2a8909702103_1532x480.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><strong>evcon</strong>, and <strong>evlis</strong> are other examples of loops in "Lisp in Lisp" code</figcaption></figure></div><div><hr></div><p>We're almost there! There is one last thing, and we're done. The <strong>eval</strong> function actually takes two arguments in the original Lisp. The first is the expression (s-exp) of course. The second is the environment, which is yet another list (of key/values). Environment maintains variable binding for the LAMBDA case by mapping variable names to their corresponding values. &nbsp;</p><p>For example, when you define a function with x variable then substitute that function with data, the data gets binded (with <strong>pairlis</strong>) to the x symbol and is then stored/appended to the environment list. When x is needed, it gets looked up (with <strong>assoc</strong>) and subtitued back to expression. The specific technique for this binding is known as <a href="https://en.wikipedia.org/wiki/Scope_(computer_science)">dynamic scoping</a>. </p><p>Here is the full 'Lisp in Lisp' code in Python:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!98DG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!98DG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 424w, https://substackcdn.com/image/fetch/$s_!98DG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 848w, https://substackcdn.com/image/fetch/$s_!98DG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 1272w, https://substackcdn.com/image/fetch/$s_!98DG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!98DG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png" width="1354" height="1550" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1550,&quot;width&quot;:1354,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:352315,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!98DG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 424w, https://substackcdn.com/image/fetch/$s_!98DG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 848w, https://substackcdn.com/image/fetch/$s_!98DG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 1272w, https://substackcdn.com/image/fetch/$s_!98DG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7161bbe-d80e-42b9-8b93-1a70bbab2a57_1354x1550.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Original 'Lisp in Lisp' in Python</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bOUs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bOUs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 424w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 848w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bOUs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png" width="1456" height="214" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:214,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:83226,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bOUs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 424w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 848w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 1272w, https://substackcdn.com/image/fetch/$s_!bOUs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F909b94d3-7004-4029-b03c-de794601f3f7_2174x320.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Lambdas at last!</figcaption></figure></div><p>Full code available on <a href="https://gist.github.com/aburjg/1dffba5516095050089f6ea293cb782b#second">github gists</a><br><br>Find me on <a href="https://twitter.com/aburjg">Twitter @aburjg</a></p><div><hr></div><p><strong>Helpful resources:</strong></p><ul><li><p>https://inst.eecs.berkeley.edu/~cs61a/fa14/assets/interpreter/scheme.html</p></li><li><p>http://languagelog.ldc.upenn.edu/myl/llog/jmc.pdf</p></li><li><p>https://justine.lol/sectorlisp2</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aljamal.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading MOHAMMED JAMAL! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>