Learning Lisp

The Road To Lisp

Re: Don’t Study, Do.

Posted by j1p on May 3, 2006

I think the Lisp bug has bitten me.

After an uneventful morning, consisting of daydreaming through class and a quick lunch, I rushed to get to work on time. Now, I really do enjoy working here, I tend to look forward to the 3 hours a day I get to spend on a computer, hacking away(normally at html, ColdFusion, or CSS) without being interrupted by neighbors, etc, but I'd rather be doing some other things. I get to work, and to my surprise my 3 co-workers all seemed to have taken the day off. I got through all the webteam stuff in 30 minutes, so I figure I might as well read up a bit on Lisp.

While browsing technorati, I came across a post, How To Advance in InfoSec: Don't Study, Do. While this post has little to do with Lisp in general, it is extremely relevant to what I'm doing here. Here's a quote straight from the post(actually the only part that even mentions Lisp):

Don’t read three books in a row on Lisp. Take a program you’ve written in a previous language and redo it in Lisp. Use your three books as a reference.

That was exactly what I was doing, I checked out 3 books on Lisp, and was reading through them like a tutorial. I need some real experience working with Lisp, making it do something I want it to do, not just what they tell me it can do.

So, I'm going to try to rewrite my first CS102 assignment from Java to Lisp. Here are the details as posted by my professor.


  1. You need to create a class called Bag that contains an array of items. You may assume that the items are all integers (the weights of the various items in pounds) and that the capacity of the bag is twenty pounds. Your private variables will include this array of integers, a count of how many items are in the array, and any other data you feel you will need. The methods for the class should include the any constructors that you will need, any query functions (such as examining the weight currently held in the bag), and a method to insert a new item into the bag. You may, of course, include any other methods that you feel you need.
  2. Your input will be a list of integers. You may read it in from the screen or from a text file (a text file is probably easier). If you read it in from a text file, be sure to prompt the user for the name of the file that is to be used for the input. If you input the weights from the screen, be sure to give the user sufficient prompts. If any bad data (such as a character) is in the input, ignore it and proceed to the next input.
  3. If your input is: 15 13 4 9 6 1 , for example, your output should be of the form:

    Bag 1: 15 4 1

    Bag 2: 13 6

    Bag 3: 9

  4. You should create a second class for packing the bags that contains a method called pack(), which reads in your data and packs them into the bags. You will need a method to print your results, which calls a print method in the bag class. Your main method should be very short, essentially calling pack() and print().

  5. Be sure to include comments in all of your methods

Alright, so this looks like it is going to be much simpler in Lisp than in Java, for the fact that practically all it is is list manipulation, Lisp's specialty. I have no need to make the Bag class contain an array of items, it can simply be a List of items in Lisp.

To make this work as close to the specifications as I can, I am going to need to learn more about CLOS, though most of the methods for the classes look like they will be pretty simple.

I have a 10 page paper to write for class tomorrow, but I'll probably hold that off until after I get home and use SLIME to write up some preliminary functions that will help for the final Lisp-version of Bag.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: