The Hobbit Hole

In a hole there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.

2/21/2006

Link to the Past

Filed under: General,RPG — bilbo @ 1:49 pm

Wow, Link is 20 years old today!

I doubt there is any character as revered as Link in the entire gaming universe.

2/16/2006

Which Sci-Fi crew are you?

Filed under: General — bilbo @ 5:49 pm

I’ve taken a few of these quizzes at the behest of friends, and I always find the results funny. Most of these shows I’ve either never seen, or at most have seen a half a dozen episodes.

You scored as SG-1 (Stargate). You are versatile and diverse in your thinking. You have an open mind to that which seems highly unlikely and accept it with a bit of humor. Now if only aliens would stop trying to take over your body.

SG-1 (Stargate)
75%
Andromeda Ascendant (Andromeda)
69%
Deep Space Nine (Star Trek)
69%
Galactica (Battlestar: Galactica)
63%
Bebop (Cowboy Bebop)
63%
Babylon 5 (Babylon 5)
63%
Moya (Farscape)
63%
FBI's X-Files Division (The X-Files)
56%
Serenity (Firefly)
50%
Nebuchadnezzar (The Matrix)
50%
Enterprise D (Star Trek)
50%
Millennium Falcon (Star Wars)
44%

Your Ultimate Sci-Fi Profile II: which sci-fi crew would you best fit in? (pics)
created with QuizFarm.com

2/15/2006

Unwrapping a Lisp Package

Filed under: Programming — bilbo @ 5:36 pm

I don’t consider myself a complete n00b to Lisp, but at the same time, I definitely am learning.

One of the greatest features of Lisp is the ability to simply recompile a single function rather than having to save a file and restart an application.  Hit C-c, C-c and the function is replaced with your new, correct version.  That is, unless it’s in a package.

For instance, when working on my csv reader, I would load the file with C-c l.  This would then load the symbols into the image, within the package org.hobbit-hole.csv.  I would then use the package, and everything would work fine.  Then I would find a bug, fix it in the source, and hit C-c, C-c, which would send the defun to the image.  Unfortunately, I would get an error similar to this frequently upon testing:

;;; Warning: Function not defined: CSV-SPLIT-STREAM
;;; An error occurred in function #< COMPILED-FUNCTION: #xD021B8 >:
;;; Error: The function CSV-SPLIT-STREAM is undefined
;;; Entering Corman Lisp debug loop.
;;; Use :C followed by an option to exit. Type :HELP for help.
;;; Restart options:
;;; 1   Abort to top level.

Doh! The problem is that the function csv-split-stream isn’t in the default cl-user package, but is internal to the org.hobbit-hole.csv package. Also inconvenient is that when I received this error, the reader created a symbol in the current package, which means that all subsequent calls to csv-split-stream will use this bogus symbol and get the error, unless the current package is changed or the symbol is uninterned from the current package, something that isn’t always practical to do. Not a huge problem, but a consistent hassle for forgetful programmers such as myself.

Despite the debugging inconvenience, packages are good. Lisp packages allow you to modularize your code, which is a good thing to do no matter what language you use. It therefore makes sense to put your code within packages. So, what are the options when debugging your code?

  • Remember to always switch packages first
  • Unintern accidental symbols
  • Wait to use defpackage until the software needs no more modification
  • Comment out the defpackage(s) when debugging so everything loads into the current package

The first two are inconvenient, the third never really comes to pass, and the last is good, except I sometimes forget.

Enter reader macros, specifically #+ and #- (sharpsign plus and sharpsign minus in the CLHS).  #+ and #- are roughly analogous to #ifdef and #ifndef in C. When a #+:symbol precedes a form, that form is only evaluated when that symbol is present in the *features* list.  Vice versa for the #- reader macro.

So, putting these in front of the defpackage and in-package during testing can help you avoid the “Function not defined” error that happens when you’re in the wrong package. Being a standard practice, it is also much easier to remember, similar to remembering to undefine DEBUG when compiling a release version of a C++ program.

So, the top of the csv reader looks like this:

; comment this out when released
#+:cormanlisp
(nconc *features* '(:csv-testing))

(in-package :cl-user)

#-:csv-testing
(defpackage "ORG.HOBBIT-HOLE.CSV"
    (:nicknames "CSV")
    (:use "CL")
    (:export
        "ITERATE-CSV-STRING"
        "ITERATE-CSV-STREAM")
    (:documentation "A csv library.  CSV means comma separated
values.  It will read a line at a time, and return it as list of separated
strings.  Quotes are considered part of a continuous string.
Delimiters other than #\, may be specified, such as tabs.

The following are functions defined for this package (see their
documentation):

iterate-csv-string
iterate-csv-stream"))

#-:csv-testing
(in-package :csv)

#+:csv-testing
(format t "In testing mode~%")
#-:csv-testing
(format t "In release mode~%")

As you can see, I also have a print out that tells me what mode I’ve loaded something in.

There might be some way to use eval-when to automatically do this. I’ll have to do more research.

2/14/2006

Steinbrenner Class Act

Filed under: General — bilbo @ 11:10 am

Huh, who’d a thunk it?  It looks as if George Costanza didn’t rub off on him after all.

I’m glad to be a Yankees fan, though I’m a Mariners fan first and foremost.
 
:)