BuddhistCatholicContemplativeEvangelicalGeneral ChristianHinduJewishLatter-day SaintMuslimNew VisionsProgressive Christian
Beliefs
- Buddhist
- Catholic
- Contemplative
- Evangelical
- General Christian
- Hindu
- Jewish
- Latter-day Saint
- More Voices
- Muslim
- New Visions
- Pagan
- Progressive Christian
Topics
- Religion News
- Food and Religion
- Sports and Religion
- Religious Art
- Religious Music and Entertainment
- Religious Events
- History and Religion
- Style and Religion
- Politics and Religion
- Women in Religion
- Recreation Outdoors and Religion
- Business Finance and Religion
- Careers Workplace and Religion
- Education and Religion
- Family Parenting and Religion
- Health Fitness and Religion
- Home and Religion
- Relationships and Religion
- Technology and Religion
- Travel and Religion
Columnists
- Buddhist Columnists
- Business Finance and Religion Columnists
- Careers Workplace and Religion Columnists
- Catholic Columnists
- Contemplative Columnists
- Education and Religion Columnists
- Evangelists Columnists
- Family Parenting and Religion Columnists
- General Christian Columnists
- Health Fitness and Religion Columnists
- Hindu Columnists
- History and Religion Columnists
- Home and Religion Columnists
- Jewish Columnists
- More Voices Columnists
- Latter Day Columnists
- Muslim Columnists
- New Visions Columnists
- Nonreligious Columnists
- Pagan Columnists
- Politics and Religion Columnists
- Progressive Columnists
- Recreation Outdoors and Religion Columnists
- Relationships and Religion Columnists
- Religion News Columnists
- Religious Art Columnists
- Religious Events Columnists
- Religious Music and Entertainment Columnists
- Sports and Religion Columnists
- Style and Religion Columnists
- Technology and Religion Columnists
- Travel and Religion Columnists
- Women in Religion Columnists
Resource Library
- 2026 Calendar
- Library of World Religions
- The 100 Most Holy Places on Earth
- Patheos Answers
- Podcasts
- Videos
- Faith Leaders Database
- Anglican Episcopalian
- Bahai
- Baptist
- Buddhism
- Christianity
- Confucianism
- Eastern Orthodoxy
- Hinduism
- Holiness and Pentecostal
- ISKCON
- Islam
- Judaism
- Lutheran
- Methodist
- The Church of Jesus Christ of Latter-day Saints
- New Age
- Paganism
- Presbytarian and Reformed
- Protestantism
- Religion Behind the Scenes
- Roman Catholic
- Scientology
- Shia Islam
- Sikhism
- Sufism
- Sunni Islam
- Taoism
- Zen
- See all religions
Research Tools
Ad-Free & Subscriber Log-In Subscription Support
Ad-Free & Subscriber Log-In Subscription Support
- Trending:
- Advent
- |
- Forgiveness
- |
- Thanksgiving
- |
- Election
- |
- Seasonal Holidays
- |
- Marriage
Cry 'Woof'
-
Series
- Home
- Catholic
- Adventures in Clojure: The World is Mine!
Adventures in Clojure: The World is Mine!
Last updated on: July 12, 2014 at 3:15 am by willduquette
Adventures in Clojure: The World is Mine! 2014-07-10T21:16:00-05:00 willduquette
Patheos Explore the world's faith through different perspectives on religion and spirituality! Patheos has the views of the prevalent religions and spiritualities of the world.
So I’m, in a rather desultory fashion, putting together a simple text adventure in the Clojure programming language. (You can find the code at GitHub, should you be interested.)
The first thing you need in a text adventure game is a world to move around in. The world usually consists of a collection of rooms. Each room can have any number of links to other rooms; each link is in a particular direction. Directions include the four cardinal directions (north, south, east, and west) and their quarters (northeast, northwest, southeast, southwest); up and down, and sometimes in and out. Mathematically speaking, what we have is a directed graph, with rooms for the nodes and links between rooms as the edges.
A room has quite a bit of data associated with it. A room will have at least the following:
- A name
- A detailed description (which might be partially or completed computed)
- The links to other rooms (ditto)
In addition, a room is usually a container for objects. It may contain some objects as the game starts, and the player can usually drop objects and leave them behind.
In Clojure, it’s common to represent objects like rooms as maps. A map is a table of keys and values: given the key, you can retrieve the value. (It’s called a “map” because it’s a mapping from keys to values.) The keys and values can be any kind of Clojure data value (including quite complicated ones), but when you use a map to represent an object the keys are usually Clojure keyword symbols.
Here’s an example of a room object:
{:name "Home Base"
:description "Your apartment. Looks kind of scruffy."
:links {:out :street
:south :bedroom
:east :kitchen}}
The words beginning a colon (e.g., :name) are keyword symbols. I’ve specified the room’s name, description and links, all in one concise data value.
Note that the value associated with the key :links is another map: a map from directions to room IDs.
Room IDs? Where did that come from? What is this room ID of which you speak?
In a language like C or Java or Tcl it’s common to keep object records in a collection of some kind, and look them up as needed given an ID. In C it would often be a pointer; in Tcl it would be a string. In Clojure, you might use a keyword; and that’s what I’m doing. I’m going to assign each room a unique ID, a keyword, and use that to refer to the room. When I want to pass a room to a function, I’ll pass the keyword and let the function look up the room’s data.
In short, I’ll quite literally have a map of rooms:
(def rooms {
:home {...}
:bedroom {...}
:kitchen {...}
:street {...}})
This is somewhat perverse in Clojure code; I understand that the done thing is to pass the room’s full map to functions, and even use it as a key in other maps. I’m not used to thinking that way, but I didn’t choose this
structure just because it’s familiar.
The problem with the map of rooms is that it’s a cyclic graph. That means that if you want to define the links between rooms as you define the rooms, you need to be able to link to rooms that haven’t been defined yet…and that means using some kind of indirection.
To put it another way: when I define the “Home Base” room, I haven’t yet defined the :street room; but I know that its ID is going to be :street so I’ll use that in the link. I’ll get around to defining the details of the :street room later on in the code.
Previous Post

July 11, 2014
Bertie Wooster Sings the Blues!
Next Post

July 13, 2014 Lumen Fidei: The Crystallized Love of God
Browse Our Archives
Select a Category Admin App o' the Morning Ask the Dogmat Believing Thomas Bits of Fiction Blasts from the Past Bootstrapping the Interior Life Catholic Mom Christian Living Deep Thoughts from the Doghouse Dominicana Evangelii Gaudium Interviews It Was A Dark and Stormy Night Links to This and That Lumen Fidei Meme Watch On Writing Operation Gratitude Pedant Errant Photography Quill Random Barkings S'Mary's World Shakers of Salt Software Development The Dog Whistler The Dogmat Sez Third Orders Thomas Aquinas Uncategorized Vikings at Dinos Woof Guide to Cinema Woof Guide to History Woof Guide to Literature Woof Guide to Obscure Catholic Music Woof Guide to Philosophy Woof Guide to Popular Music Woof Guide to Technology Woof Guide to Theology Words I Wish I'd Written Works For Me
Select a Month September 2016 August 2016 June 2016 May 2016 April 2016 March 2016 February 2016 January 2016 December 2015 November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 January 2015 December 2014 November 2014 October 2014 September 2014 August 2014 July 2014 June 2014 May 2014 April 2014 March 2014 February 2014 January 2014 December 2013 November 2013 October 2013
Follow Us!
TAKE THE
Religious Wisdom Quiz
What Christian tradition is noted for its belief in nonresistance and simple living?
Select your answer to see how you score.
Anglican Episcopalian Methodist Amish
Related posts from Cry 'Woof'
Second Look: Amazon Echo after One Week
First Look: Amazon Echo, or Alexa Tells You...
Book Reader Notes: Kindle vs. iBooks vs. Google...
TRENDING AT PATHEOS Catholic
Choosing Virtue Over Luxury And Self-Interest
St. Basil the Great understood two different ways we can find our...
Why AI Needs Limits: Lessons From The Sorcerer’s...
The story of the Sorcerer’s Apprentice is famous in the modern age...
Faith, Reason, and Transubstantiation
“It would be easier for the world to survive without the sun...
If Baptism Washes Away Sin, Why Do Catholics...
The seven sacraments stand as the foundation of Catholic ecclesial life. The...
The Power of Setting a Good Example
Remember last August when the Chicago White Sox hosted a "Pope Hat...
How Grandma Tourism Helps Grandparents Live Their Vocation
Grandma, The New Travel Influencer What started as a nostalgia-inspired social media...
view all Catholic blogs
Ad-Free & Subscriber Log-In Subscription Support
- About Us
- 2026 Calendar
- Videos
- Podcasts
- Library of World Religions
- Faith In Media Tracker
- Advertise With Us
- Write for Us
- Privacy Policy
- Terms of Service
- Do Not Sell My Data
- Contact Us
- Radiant Digital
- Manage Newsletter Subscriptions
- Unsubscribe From Notifications
- Sitemap
Copyright 2008-2026, Patheos, part of the Radiant Digital network of media brands. All rights reserved.
Subscription Support Ad-Free & Subscriber Log-In









