<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Duane Edmonds on Medium]]></title>
        <description><![CDATA[Stories by Duane Edmonds on Medium]]></description>
        <link>https://medium.com/@duane.edmonds?source=rss-c8959736aeda------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KsYrSA3U0D3x_GYm</url>
            <title>Stories by Duane Edmonds on Medium</title>
            <link>https://medium.com/@duane.edmonds?source=rss-c8959736aeda------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:23:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@duane.edmonds/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sudoku: The elegance of language-oriented programming in Scheme]]></title>
            <link>https://medium.com/@duane.edmonds/sudoku-language-oriented-programming-in-scheme-c798c6e1a4c4?source=rss-c8959736aeda------2</link>
            <guid isPermaLink="false">https://medium.com/p/c798c6e1a4c4</guid>
            <category><![CDATA[lisp]]></category>
            <category><![CDATA[sudoku-solver]]></category>
            <category><![CDATA[scheme]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Duane Edmonds]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 23:01:42 GMT</pubDate>
            <atom:updated>2024-04-12T23:01:42.769Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>There are certain languages that offer not just tools for creating software but a canvas for expressing ideas elegantly and with incredible precision. Among these, Scheme — a dialect of Lisp — stands out for its unique combination of simplicity and power. Its macros and first-class functions allow superb dexterity in functional and language-oriented programming, where the language itself can be molded and stretched to fill the problem at hand. This blog post explores this beautiful aspect of Scheme through the lens of a backtracking Sudoku solver, demonstrating the language’s ability to describe a solution to such a nuanced problem.</p><p>Scheme, with its minimalist syntax and powerful macro system, encourages a different way of thinking about programming. It’s not just about writing code; it’s about designing a language (a domain-specific language) tailored to the specific problem you are trying to solve. This approach is particularly helpful when solving complex problems that can be described through the composition of simpler pieces. Sudoku, a logic-based number-placement puzzle, itself presents an intriguing problem: fill a 9x9 grid so that each column, each row and each of the nine 3x3 subgrids contain all of the digits from 1 to 9.</p><p>First-class functions allow languages like Scheme to treat functions as data, meaning they can be passed as arguments to other functions, returned as values from functions, and assigned to variables. This flexibility is crucial for creating high-level abstractions and manipulating the code itself as data. This enables more expressive and concise solutions to complex problems, like navigating the possibilities in a Sudoku puzzle through recursion and the use of higher-order functions.</p><p>And without getting into detail, macros are “programs that write programs” (Doug Hoyte, Let Over Lambda, 2008). Macros let you manipulate and extend the language on a higher plane. The language is superbly flexible. It’s like working with clay. An example, you can write a recursive interpreter for the language elegantly in the language. It “eats itself” (see <a href="https://sarabander.github.io/sicp/html/4_002e1.xhtml#g_t4_002e1">metacircular evaluator</a>, Structure and Interpretation of Computer Programs, 1996).</p><h3>A backtracking solver</h3><p>Let’s dive into one implementation of a Sudoku solver in Scheme. The solve-board function that implements the heart of the backtracking algorithm is shown below. Scheme&#39;s ability to mold and extend the language allows the algorithm to be defined as a description of what it does. Much of what it describes can be understood without much familiarity with the language. The code looks for the position of the first empty cell (hole) on the board (get-first-hole-pos). If it doesn&#39;t find a hole, the board is already solved.</p><p>Upon finding a hole, it iterates over valid candidate values (valid-values), checking if they can be placed in the hole according to the rules of the game (candidate-allowed?). If the candidate is allowed, it fills the hole (set-pos-value). Then the function recursively invokes itself on a new version of the board with the hole filled. If the recursive path succeeds (board-solved?), we have a solution. Return the solved board using a continuation. If the path we&#39;re in fails (returns an empty list instead of a solved board), we backtrack and try the next valid candidate. If all candidates fail, no solution exists.</p><p>Look through the code and decide how well you think it describes what it does.</p><p>The full implementation is available on <a href="https://github.com/usefulmove/usefulmove/blob/main/lop/sudoku.scm">GitHub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EKS3WLpLfbnMXTvP" /></figure><h3>Some helper functions</h3><p>The Sudoku board is modeled here as a simple one-dimensional list with either valid cell values (1–9) or 0s indicating a hole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/0*Jg69Pu-7HakhpA3t" /></figure><p>Maths are used to determine which row, column, or subgrid (box) any position on the board belongs to. This is calculated in the get-row, get-col, and get-box helper functions, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/0*fuOu_au7qH88Gwjg" /></figure><p>Mapping each of the index positions for the board to the corresponding get-[xxx] helpers helps visualize how their behavior. The mapping of the get-box function is shown as an example below. The output can be seen in the comment block below the code. Note that the range function is used here to returns a list of numbers from 0 through 80 (the indices of each cell on the board).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/0*6hZQ8xB-rfCNkUCw" /></figure><p>Finding the first hole position is done by searching for the first 0 in the list (board).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*KYDzWz6kqL6JJZVD" /></figure><h3>Encoding the rules</h3><p>The rules of the game are encoded in the candidate-allowed? predicate function. The function looks at the values in the row, column, and box that correspond to a specific position, and determines if a candidate (proposed) value is already in use. candidate-allowed? uses get-forbidden-candidates, a function that returns a list of all of values already being used (in the same row, column, or box) for a specific position on the board. The code for candidate-allowed? and get-forbidden-candidates (and an example of one of the get-[xxx]-values functions) are copied below. Notice each one is concise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/0*5-hgw1hggxfzvdZo" /></figure><h3>Conclusion</h3><p>I hope that by walking through this solution, you have a sense of not just the elegance and power of a language-oriented approach, but also a sense of how it can be used to solve complex problems with clarity and precision. Scheme, with its minimalist syntax and incredible flexibility, isn’t just a language — it becomes a way of reasoning about and describing a solution your problem. It allows you to more directly express a solution in a manner just as nuanced as the problem you’re solving.</p><p>The code for the algorithm is available on <a href="https://github.com/usefulmove/usefulmove/blob/main/lop/sudoku.scm">GitHub</a>. You can use <a href="https://racket-lang.org/">Racket</a> to run it and make changes. Look through the code, and let me know what you think. Can you see this approach leading to better code? Do you have another implementation (in another language?) that you want to share?</p><p>You can see the algorithm in action below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*5MvWMEqjy78BKRwcgGn7Ew.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c798c6e1a4c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Language-oriented development using functional programming fundamentals]]></title>
            <link>https://medium.com/@duane.edmonds/language-oriented-development-using-functional-programming-fundamentals-4aed0d752835?source=rss-c8959736aeda------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aed0d752835</guid>
            <category><![CDATA[scheme]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Duane Edmonds]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 21:10:26 GMT</pubDate>
            <atom:updated>2024-01-08T21:10:26.827Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hg5ZiX7zkNDYXovXmSx19A.png" /></figure><p>In the world of software development, as with any craft, choosing the right tool and methodology can spell the difference between a masterpiece and a muddled mess. Enter language-oriented development using Scheme, coupled with the core fundamentals of functional programming. Together, these paradigms form a powerful duo that can transform the way you approach complex problems, offering clarity, flexibility, and a deep level of expressiveness.</p><h3>Why Language-Oriented Development?</h3><p>Imagine you’re a sculptor, and for every unique piece of art you want to create, you could conjure the perfect tool that makes the sculpting process feel almost magical. That’s the essence of language-oriented development. Instead of bending your problem domain to fit the constraints of an existing programming language, you shape a language (a DSL) around your specific needs.</p><ul><li><strong>Tailor-Made Solutions</strong>: With a DSL, you capture the nuances of your domain, providing constructs that map directly to domain concepts. This clarity can drastically reduce the mental overhead when translating real-world problems to code.</li><li><strong>Higher Abstraction, Less Boilerplate</strong>: Language-oriented development can lead to solutions that are concise and straightforward, eliminating the boilerplate that often comes with more general-purpose languages.</li></ul><h3>The Brilliance of Scheme in Language-Oriented Development</h3><p>While language-oriented development can be pursued with many languages, Scheme, a minimalist dialect of Lisp, shines particularly bright in this arena.</p><ul><li><strong>Syntactic Malleability</strong>: Lisp languages, Scheme included, are famous for their homoiconicity — their code and data share the same structure. This feature makes them uniquely suited for creating DSLs, allowing for the easy creation and transformation of code as data.</li><li><strong>Elegant Simplicity</strong>: Scheme’s minimalist nature makes it a blank canvas, ready to be shaped and molded to your domain. It does not burden the developer with superfluous constructs, allowing the DSL’s domain concepts to stand front and center.</li></ul><h3>The Core Fundamentals of Functional Programming: A Perfect Match</h3><p>Now, imagine coupling the power of language-oriented development with the foundational principles of functional programming.</p><ul><li><strong>Immutability and Pure Functions</strong>: At the heart of functional programming is the notion of pure functions and immutability. In practice, this translates to predictable and consistent code. When combined with a DSL, you ensure that your tailored language not only speaks fluently of the domain but also maintains a rigorous standard of clarity and reliability.</li><li><strong>Higher-Order Functions and Recursion</strong>: Scheme, with its functional nature, allows for elegant recursive solutions and the use of higher-order functions. This means your DSL can benefit from compact, expressive patterns, enabling complex operations to be distilled into intuitive, domain-specific constructs.</li><li><strong>Composability</strong>: Functional programming thrives on the principle of building solutions by composing smaller, reusable pieces. With a DSL designed in Scheme, you can create modular, composable constructs that align directly with your domain, leading to code that is both efficient and readable.</li></ul><h3>Concluding Thoughts</h3><p>By marrying language-oriented development in Scheme with the core tenets of functional programming, developers are gifted with a framework that resonates with expressiveness, flexibility, and precision. It’s not just about crafting solutions; it’s about crafting the <em>language</em> that understands your domain as deeply as you do and then using that language to sculpt elegant, functional solutions.</p><p>In an age where software complexity is ever-growing, perhaps it’s time to consider the powerful synergy of these paradigms. Shape your language, shape your solution, and discover the unparalleled power of precision with Scheme and functional programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aed0d752835" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>