<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Thomas Seeley - scheme</title><id>https://www.tseeley.com/tags/scheme/atom.xml</id><updated>2024-07-04T00:00:00+00:00</updated><generator>tseeley.com</generator><link href="https://www.tseeley.com/tags/scheme/atom.xml" rel="self" type="application/atom+xml"/><link href="https://www.tseeley.com" rel="alternate" type="text/html"/><subtitle>Posts about software and making things.</subtitle><entry><title>Scheme-ing</title><id>https://www.tseeley.com/posts/schemeing/</id><updated>2024-07-04T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/schemeing/" rel="alternate" type="text/html"/><published>2024-07-04T00:00:00+00:00</published><content type="html">
&lt;p&gt;I’ve been reading &lt;a href=&quot;https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/index.html&quot;&gt;SICP&lt;/a&gt; on and off. To be honest, I’ve only made it a few chapters in and I think that’s as far as I’ll go.&lt;/p&gt;
&lt;p&gt;Around the same time I read &lt;a href=&quot;https://bookshop.org/books/wolf-in-white-van/9781250074713&quot;&gt;&lt;em&gt;Wolf in White Van&lt;/em&gt;&lt;/a&gt; by John Darnielle. It’s a novel about a guy who runs a &lt;a href=&quot;https://en.wikipedia.org/wiki/Interactive_fiction&quot;&gt;text-based adventure game&lt;/a&gt; by mail. Players send in their moves, he sends back what happens. The game is called Trace Italian! The whole book is told in reverse, which gives it this strange gravity. You know where the story ends up before you know how it started.&lt;/p&gt;
&lt;p&gt;I thought it would be fun to build a text adventure in Scheme. So I did!&lt;/p&gt;
&lt;section id=&quot;The-Game&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#The-Game&quot;&gt;The Game&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It’s small. Four rooms, directional movement, a game loop. No items, no puzzles, no win condition. Just the skeleton of a world you can walk around in.&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;scheme&quot;&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;define &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;rooms
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;living-room &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the living room. There is a door to the north and a kitchen to the west.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kitchen &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the kitchen. There is a living room to the east.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;hallway &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the hallway. There is a living room to the south and a bedroom to the north.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;bedroom &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the bedroom. There is a hallway to the south.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)))
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rooms are lists. Connections between rooms are lists. The game state is which room you’re in.&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;scheme&quot;&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;define &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(game-loop)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (describe-current-room)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;((command (get-command)))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;cond &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;north) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;north))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;south) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;south))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;east) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;east))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;west) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;west))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;quit) (display &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;Goodbye!&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                                (&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;newline&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                                (exit))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          (else (display &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;Invalid command.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                (&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;newline&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    (game-loop)))
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The game loop is a recursive function that describes where you are, reads a command, acts on it, then calls itself. No &lt;code&gt;while&lt;/code&gt; loop, no mutable iterator. Just a function that calls itself forever until you quit.&lt;/p&gt;
&lt;p&gt;It’s a good reminder that you don’t need much to make something interactive. Four rooms and a prompt. That’s a world you can walk around in.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/iamseeley/just-scheme-things/blob/main/adventure.scm&quot;&gt;full source&lt;/a&gt; is about 60 lines. There’s also a &lt;a href=&quot;https://github.com/iamseeley/just-scheme-things/blob/main/tic-tac-toe.scm&quot;&gt;tic-tac-toe&lt;/a&gt; in the same repo from the same weekend.&lt;/p&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;scheme&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/maze-playground/&quot;&gt;Maze Playground&lt;/a&gt;&lt;/p&gt;
</content></entry></feed>