personal-website/content/posts/scheme-journey.html

164 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en" class="bg-base-bg">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A journey into Scheme programming and building a symlink manager">
<meta property="og:title" content="A Journey into Scheme: Building a Simple Symlink Manager with Guile Scheme">
<meta property="og:description" content="Learning Guile Scheme and building a practical tool for managing symlinks">
<meta property="og:url" content="https://glenneth.org/content/posts/scheme-journey">
<title>Journey into Scheme - Glenn Thompson</title>
<link href="../../dist/styles.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Merriweather:wght@400;700&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
</head>
<body class="bg-base-bg text-palenight-50">
<nav class="fixed w-full bg-base-darker/80 backdrop-blur-sm shadow-sm z-50 border-b border-palenight-400/20">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<a href="/" class="flex items-center font-serif text-xl font-bold text-accent-purple">Glenn Thompson</a>
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<a href="/#about" class="nav-link text-accent-blue hover:text-accent-cyan">About</a>
<a href="/#blog" class="nav-link text-accent-blue hover:text-accent-cyan">Blog</a>
<a href="/#projects" class="nav-link text-accent-blue hover:text-accent-cyan">Projects</a>
</div>
</div>
</div>
</nav>
<main class="pt-24 pb-16 px-4">
<div class="max-w-4xl mx-auto">
<div class="content text-palenight-100 space-y-6">
<div class="flex items-center justify-between mb-8">
<a href="/" class="inline-flex items-center text-accent-blue hover:text-accent-cyan transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd" />
</svg>
Back to Home
</a>
<time datetime="2024-09-24T09:30:00" class="text-palenight-300">September 24, 2024</time>
</div>
<header class="mb-8">
<h1 class="text-4xl font-serif font-bold text-accent-yellow">A Journey into Scheme: Building a Simple Symlink Manager with Guile Scheme</h1>
<div class="flex items-center gap-4 text-palenight-300 mt-4">
<time datetime="2024-09-24T09:30:00">September 24, 2024</time>
<span></span>
<span>By Glenn Thompson</span>
</div>
</header>
<section class="prose prose-palenight max-w-none">
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">Introduction</h2>
<p class="mb-4">I've spent my career as an electrical engineer, not a software developer. However, my recent journey in to GNU/Liniux required a tool for managing symlinks, and that's how I began learning Scheme—specifically Guile Scheme. I'm writing this post to share how I built <code class="text-accent-purple">stash</code>, a utility that mimics GNU Stow's functionality, and how my learning journey was shaped by David Wilson's "Hands-On Guile Scheme for Beginners" course from System Crafters, more about this below.</p>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">How I Started with Scheme</h2>
<p class="mb-4">My programming background was <em>VERY</em> limited, I produce documents in (La)Tex but I decided to take the plunge into learning Scheme, thanks to a course led by David Wilson from System Crafters. The course, <a href="https://systemcrafters.net/courses/hands-on-guile-scheme-beginners/" class="text-accent-blue hover:text-accent-cyan">"Hands-On Guile Scheme for Beginners"</a>, was incredibly helpful in making Scheme accessible even for someone like me, without a traditional programming background. I know (La)Tex isn't a programming language, it's typesetting. But how hard can it be? Right?</p>
<p class="mb-4">The course took me through the basics of Scheme, from simple expressions to more complex concepts like functions, recursion, and working with files. This structured learning environment gave me the confidence to start building <code class="text-accent-purple">stash</code>.</p>
<p class="mb-4">The course was "instructor-led" with live meet-up sessions weekly. David has since made this course on-demand, and will be, if not already, available at the above link. Highly recommended if you are interested in taking your first steps with scheme.</p>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">Why Build Stash?</h2>
<p class="mb-4">After completing David Wilson's course, I wanted to put my newly found Guile Scheme skills into practice with a real project. It wasn't enough just to understand the language conceptually—I needed to build something tangible that solved a problem I encountered regularly in my workflow. Writing <code class="text-accent-purple">stash</code> gave me that opportunity. It allowed me to apply what I'd learned while also deepening my understanding of file manipulation, command-line tools, and conflict resolution—all within the Guile Scheme environment.</p>
<p class="mb-4">After migrating to GNU/Linux and speaking with other <a href="https://systemcrafters.net/community" class="text-accent-blue hover:text-accent-cyan">System Crafters Community</a> members, I found I needed a way to manage symbolic links and organize directories. Existing tools like GNU Stow helped, but I wanted to learn how such tools are built. I decided to write my own version using Guile Scheme to enhance my understanding of the language and to have more control over the functionality.</p>
<p class="mb-4">The goal of <code class="text-accent-purple">stash</code> is simple: allow users to move directories and create symlinks with conflict resolution, offering options to overwrite, back up, skip, or cancel the operation.</p>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">Breaking Down Stash</h2>
<p class="mb-4">The core of <code class="text-accent-purple">stash</code> revolves around:</p>
<ol class="list-decimal pl-6 mb-6">
<li class="mb-2"><strong class="text-accent-purple">Moving Directories</strong>: Using Scheme's file manipulation functions, I learned how to move directories and files around.</li>
<li class="mb-2"><strong class="text-accent-purple">Creating Symlinks</strong>: I implemented functions to create symlinks to the moved directories, ensuring that the original structure remains accessible.</li>
<li class="mb-2"><strong class="text-accent-purple">Conflict Resolution</strong>: One of the key features I wanted was handling conflicts when a file or symlink already exists at the target location. This required prompting the user for input and responding accordingly (backup, overwrite, skip, or cancel).</li>
</ol>
<p class="mb-4">Here's an excerpt of the core functionality that handles moving a source directory and creating a symlink:</p>
<pre class="bg-base-darker p-4 rounded-lg overflow-x-auto mb-4"><code class="text-palenight-100 font-mono text-sm">;;; Helper function to move source to target
(define (move-source-to-target source-dir target-dir)
"Move the entire source directory to the target directory."
(let* ((source-dir (expand-home source-dir))
(target-dir (expand-home target-dir))
(source-name (basename source-dir))
(target-source-dir (string-append target-dir "/" source-name)))
(if (file-exists? target-source-dir)
;; Conflict handling here...
...)
(rename-file source-dir target-source-dir)
(display (format #f "Moved ~a to ~a\n" source-dir target-source-dir))))</code></pre>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">What I Learned</h2>
<p class="mb-4">This project taught me a lot about not just Scheme, but programming in general:</p>
<ul class="list-disc pl-6 mb-6">
<li class="mb-2"><strong class="text-accent-purple">File and Directory Manipulation</strong>: Scheme's file handling functions were different from what I had experienced before, but they allowed for powerful manipulation of file systems.</li>
<li class="mb-2"><strong class="text-accent-purple">Command-Line Utilities</strong>: Scheme isn't just a language for academic exercises; you can write real, useful command-line tools with it.</li>
<li class="mb-2"><strong class="text-accent-purple">Problem Solving</strong>: From parsing command-line arguments to resolving conflicts with existing files, every part of the program required careful thought and consideration of edge cases.</li>
</ul>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">Guile Scheme Support Resources</h2>
<ol class="list-decimal pl-6 mb-6">
<li class="mb-4"><strong class="text-accent-purple"><a href="https://www.gnu.org/software/guile/docs/" class="text-accent-blue hover:text-accent-cyan">Guile Scheme Documentation</a></strong><br>
The official documentation for Guile Scheme, which includes tutorials, references, and the Guile Manual.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://www.gnu.org/software/guile/manual/html_node/" class="text-accent-blue hover:text-accent-cyan">Guile Reference Manual</a></strong><br>
A comprehensive manual covering core language concepts, libraries, and functions available in Guile Scheme.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="http://community.schemewiki.org/" class="text-accent-blue hover:text-accent-cyan">Scheme Wiki</a></strong><br>
A community-maintained wiki that covers various Scheme dialects, including Guile Scheme, with tutorials, guides, and general information on Scheme programming.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="http://schemers.org/" class="text-accent-blue hover:text-accent-cyan">Guile at Schemers.org</a></strong><br>
A site dedicated to Scheme with resources, libraries, tools, and documentation for Scheme and its implementations, including Guile.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://systemcrafters.net/" class="text-accent-blue hover:text-accent-cyan">System Crafters</a></strong><br>
Led by David Wilson, System Crafters provides tutorials and blog posts on Guile Scheme and other GNU tools.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://lists.gnu.org/mailman/listinfo/guile-user" class="text-accent-blue hover:text-accent-cyan">Guile Users Mailing List</a></strong><br>
Join the Guile mailing list to ask questions and engage with the Guile Scheme community.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://github.com/artyom-poptsov/guile-cookbook" class="text-accent-blue hover:text-accent-cyan">Guile Cookbook</a></strong><br>
An unofficial GitHub repository with practical code snippets and tips for Guile Scheme, covering various common use cases and tasks.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://libera.chat/" class="text-accent-blue hover:text-accent-cyan">#guile and #scheme on Libera Chat IRC</a></strong><br>
A helpful IRC channel where you can connect with other Guile users for real-time support and advice.</li>
<li class="mb-4"><strong class="text-accent-purple"><a href="https://libera.chat/" class="text-accent-blue hover:text-accent-cyan">#systemcrafters on Libera Chat IRC</a></strong><br>
A <em>SUPER</em> helpful IRC channel not only for guile and scheme, there are a huge variety of different people here. Tell them glenneth sent you.</li>
</ol>
<h2 class="text-2xl font-serif font-bold text-accent-yellow mt-8 mb-4">Next Steps</h2>
<p class="mb-4">I am still refining <code class="text-accent-purple">stash</code>, especially around its conflict resolution system and the way it handles symbolic links. But it's in a usable state, and I'm excited to continue iterating on it. You can check out the code <a href="https://codeberg.org/glenneth/stash" class="text-accent-blue hover:text-accent-cyan">on Codeberg</a>.</p>
<p class="mb-4">If you're curious about Scheme and how it can be used practically, I highly recommend checking out David Wilson's course. It's been instrumental in helping me grasp the concepts I needed to build this tool. Here's the link, again :) <a href="https://systemcrafters.net/courses/hands-on-guile-scheme-beginners/" class="text-accent-blue hover:text-accent-cyan">"Hands-On Guile Scheme for Beginners"</a></p>
</section>
</div>
</div>
</main>
<footer class="bg-base-darker text-palenight-200 py-12 border-t border-palenight-400/20">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="text-center">
<p class="text-palenight-300">&copy; 2024 Glenn Thompson. All rights reserved.</p>
<div class="webring-text mt-6">
<p class="text-palenight-300">I am part of the <a href="https://systemcrafters.net" target="_blank" class="text-accent-blue hover:text-accent-cyan">System Crafters</a> webring:</p>
</div>
<div class="craftering mt-2 flex items-center justify-center gap-4 text-accent-blue">
<a href="https://craftering.systemcrafters.net/@glenneth/previous" class="hover:text-accent-cyan"></a>
<a href="https://craftering.systemcrafters.net/" class="hover:text-accent-cyan">craftering</a>
<a href="https://craftering.systemcrafters.net/@glenneth/next" class="hover:text-accent-cyan"></a>
</div>
<p class="text-palenight-300 mt-2">
<a href="mailto:glenn@glenneth.org" class="text-accent-blue hover:text-accent-cyan transition-colors">glenn@glenneth.org</a> |
<a href="https://glenneth.org" class="text-accent-blue hover:text-accent-cyan transition-colors">glenneth.org</a>
</p>
</div>
</div>
</footer>
</body>
</html>