Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Guys I made adventures in common LISP

Name: Anonymous 2011-06-20 6:06

Reddit told me this is the place to go for LISP critiques. If anybody gets a chance could they have a look at my LISP code? Outlined on my live journal here: http://untoward.livejournal.com/472662.html and here: http://untoward.livejournal.com/472344.html

Name: Anonymous 2011-06-20 6:18

That unicorn shit isn't funny unless you're 12. Are you 12?

Name: Anonymous 2011-06-20 6:18

inb4shitstorm

Name: Anonymous 2011-06-20 6:23

>>3
wtf?

Name: Anonymous 2011-06-20 6:24

>>2
Are you a pedo? I wanted a critique on my coding, not a proposition from some sweaty pedo.

Name: Anonymous 2011-06-20 6:53

>>5 why are u so mad lets live in peace and rape ouer children together ~~

Name: Anonymous 2011-06-20 7:03

>>6
reported for pedo

Name: Anonymous 2011-06-20 7:09

Lisp is for gay paedophiles.

Name: Anonymous 2011-06-20 7:12

>>1
I like the guy who responded to one of your livejournal posts, joey.
http://a3.twimg.com/profile_images/1179743073/avatar-2010-02-09-140622.png

Name: Anonymous 2011-06-20 7:21

>>9
What's wrong with him? I bet he is just a regular guy. he probably plays minecraft, codes, goes to Uni, maybe a bit of boardgame.

Name: Anonymous 2011-06-20 7:29

>>10
It's an earth based religion, really.

Name: doublleft 2011-06-20 7:35

whatever

Name: Anonymous 2011-06-20 7:59

LISP IS GAY

Name: Anonymous 2011-06-20 8:01

Repost your code here.

Name: Page 1 2011-06-20 8:03

>>14
    joey ([info]untoward) wrote,
@ 2011-05-29 20:04:00
Previous Entry  Add to memories!  Share  Next Entry
Text adventure fun in Common Lisp
The lisp programming is going well. I've started to get more engaged by the ideas of it. This is my first introduction to the idea of functional programming and it's interesting! Right now the book is going through how to build a text adventure, and it's taking a very practical, very expandable form that I find interesting.

Every room is defined as a node, and the paths between rooms are edges. This is completely different from how I might have tried to do this in perl. Though the objects IN the rooms are defined using global variables, which isn't functional, but I suspect will be changed as the program evolves. Right now the code is REALLY dense. The recursion here reminds me of obfuscated perl japh code.

Here's what I have:

( defparameter *nodes* ' (( bedroom ( you are in a small bedroom. a
wizard is snoring loudly on the bed. ))
(front-step ( you are on the
front step. there is a
garbage-bin in front of you.))
(bathroom ( you are in the
bathroom. there is a welding
torch in the corner.))))

This sets up a list of the rooms (nodes) and also includes a brief description of them. There is some weirdness here because these descriptions are just lists, they aren't actually strings, but I am promised that this will be for the best.

Here's the function to return the description of a room:

(defun describe-location (location nodes)
(cadr (assoc location nodes)))

cadr is an insane lisp function that returns certain elements of a list. It takes various forms. The simplest of which are car and cdr. car returns the first item in a list. cdr returns everything else except the first item. cadr returns the first item in the list that is returned by cdr, that is: the second item in the original list. caddr returns the first item in the list returned after the first item is removed from the original and then the first is removed from THAT. (the third item) Good lord.



(defparameter *edges* '(( bedroom ( front-step outside door )
( bathroom
north hall))
(front-step (bedroom inside
door))
(bathroom (bedroom south
hall))))

This sets up the pathways between the rooms (edges). I actually find this very cool, and a neat way to do this. The format here is (room ( where-the-edge-leads directional-word form-of-pathway) so like, (bedroom (front-step outside door) means you use the door to go outside to the front step. Or, "a door leads outside to the front-step". Which is what this code does:

(defun describe-path (edge)
`(there is a ,(caddr edge) going ,(cadr edge) from here.))

and then, to describe all the edges from a certain node, you have this:

(defun describe-paths (location edges)
(apply #'append (mapcar #'describe-path (cdr (assoc location edges)))))

I am really enjoying this stuff. It's a bit of a puzzle, even though I've programmed before. It's fun!

(1 comment) - (Post a new comment)
   

[info]ffreak3
2011-05-30 12:52 am UTC (link)
Glad to hear you're enjoying LISP programming. :)

I almost always end up using LISP notation and ideas in general algorithms, finding them to be more elegant and simple in expressing most complex ideas.

I've been thinking of picking up Land Of LISP for myself recently, but I learn better with a lot of theory, and leaving the code practice to the student, as in LISPcraft . . . which is a bit outdated having been written in '84. Wait until you reach lambda calculus! Or when you realize the true power of car and cdr, (that is, with proper eval statements) ;)

(Reply to this)

(1 comment) - (Post a new comment)
About

    Contact
    Advertise
    Jobs
    Site News
    More...

   
Help

    Support / FAQs
    Safety Tips

Get Involved

    Volunteer
    Developers

   
Legal

    Terms of Service
    Privacy Policy
    Copyright
    Abuse Policy

LJ Labs

    LJ Aqua
    More...

   
Store

    Upgrade Account
    Virtual Gifts
    Merchandise
    More...

   

    Change language:

Current version:
    v.80.3

» View Full Sitemap
Copyright © 1999 LiveJournal, Inc. All rights reserved.

    Home
    Create an account
    Explore
    Shop
    LJ Extras
    Games

Username:         Create an Account
Forgot your login or password?
Facebook Twitter More login options
Password:    
    Remember Me
    English • Español • Deutsch • Русский…

Name: Page 2 2011-06-20 8:04

>>14
    joey ([info]untoward) wrote,
@ 2011-05-30 16:34:00
Previous Entry  Add to memories!  Share  Next Entry
more of my lisp text adventure:
With apologies to Charlie

Here's a demo of what can be done so far! I added a drop command, even though the book hasn't given one yet, because it seemed wise not to carry around that starfish.

CL-USER> (look)
(YOU ARE IN A SMALL CLEARING IN THE WOODS CHARLIE. THERE IS A MAGIC
LEOPLURIDON SLEEPING ON A ROCK. THERE IS A PATH GOING NORTH FROM HERE.
YOU SEE A AMULET ON THE GROUND.)

CL-USER> (pickup 'amulet)
(YOU ARE NOW CARRYING THE AMULET CHARLIE)

CL-USER> (walk 'north)
(YOU ARE ON A BRIDGE CHARLIE. THERE IS A PATH GOING SOUTH FROM HERE. THERE
IS A TRAIL GOING NORTH FROM HERE. YOU SEE A STARFISH ON THE GROUND.)

CL-USER> (walk 'north)
(YOU ARE AT THE ENTRANCE TO CANDY MOUNTAIN CHARLIE. CANDY MOUNTAIN. THERE
IS A TRAIL GOING SOUTH FROM HERE. YOU SEE A CANDY ON THE GROUND. YOU SEE
A LIVER ON THE GROUND.)

CL-USER> (inventory)
(YOU ARE CARRYING THESE ITEMS - AMULET)

CL-USER> (drop 'amulet)
(YOU DROP THE AMULET)

CL-USER> (look)
(YOU ARE AT THE ENTRANCE TO CANDY MOUNTAIN CHARLIE. CANDY MOUNTAIN. THERE
IS A TRAIL GOING SOUTH FROM HERE. YOU SEE A AMULET ON THE GROUND. YOU SEE
A CANDY ON THE GROUND. YOU SEE A LIVER ON THE GROUND.)

I have ideas for other characters you can interact with, but maybe the next couple chapters will show how to do that properly. So... onward!

(4 comments) - (Post a new comment)
   

[info]asakiyume
2011-05-30 08:52 pm UTC (link)
Saw this on your twitter feed and came on over--and laughed out loud. Very nice :D

(Reply to this)
   

[info]8cake
2011-05-31 09:00 am UTC (link)
You are pretty awesome, Joey Comeau. PRETTY AWESOME.
Just how many more abilities are you going to unlock?
;)

(Reply to this)
   

[info]youtooktoolong
2011-05-31 01:38 pm UTC (link)
(YOU FIND THE MAP TO CANDY MOUNTAIN CHARLIE)

(Reply to this)
   

[info]egowumpus
2011-06-02 11:43 pm UTC (link)
Sweet! Are you going to share the source code?

(Reply to this)

(4 comments) - (Post a new comment)
About

    Contact
    Advertise
    Jobs
    Site News
    More...

   
Help

    Support / FAQs
    Safety Tips

Get Involved

    Volunteer
    Developers

   
Legal

    Terms of Service
    Privacy Policy
    Copyright
    Abuse Policy

LJ Labs

    LJ Aqua
    More...

   
Store

    Upgrade Account
    Virtual Gifts
    Merchandise
    More...

   

    Change language:

Current version:
    v.80.3

» View Full Sitemap
Copyright © 1999 LiveJournal, Inc. All rights reserved.

Name: Anonymous 2011-06-20 8:14

lithp is fucking gay

Name: Anonymous 2011-06-20 8:34

>>17 i think so to u are cool

Name: Anonymous 2011-06-20 9:01

why are lists better than strings for representing strings of text?

Name: Anonymous 2011-06-20 9:11

Reddit
Livejournal
ಠ_ಠ

Audit my Lisp code
I prefer R5RS but R6RS is fine too.

Name: Anonymous 2011-06-20 9:23

>>19
Because Lisp features a vast amount of tools for list processing. List is a ``native" date structure in Lisp as a Lisp program itself is a list.

Name: Anonymous 2011-06-20 9:37

Such a wasted thread. Sorry I don't have more time to contribute, OP, or joey, if you are actually the original author looking for discussion, I'm in a bit of a hurry.

Name: Anonymous 2011-06-20 12:41

lisp is for fags

Name: Sarah 2011-06-20 12:46

Sarah in every field

Name: Anonymous 2011-06-20 12:49

sum prlp wen facd w/ a problem dey think 'i no use regaxum ' now their 2 probloms

Name: Anonymous 2011-06-21 4:25

>>1
I LOVE YOU! I LOVE YOUR CODE! I READ IT 5 TIMES! KEEP POSTING!

Name: Anonymous 2011-06-22 5:19

Name: Anonymous 2011-06-22 5:59

>>27
0chan.ru
Back there, rooster.

Name: Anonymous 2011-06-22 11:44

Name: Anonymous 2011-06-23 18:40

>>2
Back when I was 12 people were coding ANSI C compilers. Though I fail to remember which language was used.

Don't change these.
Name: Email:
Entire Thread Thread List