CL-WHO and a n00b gotcha!

Well, this may be stating the obvious but just recently I decided to use it for the first time ever to generate a static HTML page reporting on the 'system' table of a Drupal installation; I wanted to see what modules where installed and whether or not they were enabled.

Getting to the point, I installed CL-WHO into my SBCL setup and tried the examples from Ed Weitz-s site and they worked until I got to one of the ones that uses the (str ...) form, as soon as I hit RETURN the SBCL back-trace popped up complaining that the function STR was undefined!

Here's the code that caught me out...
[lisp]
(with-html-output (*http-stream*)
(loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
("http://marcusmiller.com/" . "Marcus Miller")
("http://www.milesdavis.com/" . "Miles Davis"))
do (htm (:a :href link
(:b (str title)))
:br)))
[/lisp]
Stunned silence ensued for a couple of minutes while my mind started to figure out all the things I could have screwed up installing with ASDF or something. I stared and stared and stared until I could stare no more.

After being a hacker for 25+ years now I have formulated what I call The Golden Rules Of Programming, which in condensed form are as follows :-

  1. You spelt it wrong.
  2. See rule 1.

And then the penny dropped! the STR function so mysteriously undefined was kind of spelled incorrectly because... wait for it... I was in CL-USER which means it was looking for a function called STR in that package!! DOH!!

A quick change of the code to (cl-who:str) was all that was required and all the examples on the page mentioned above then worked just fine. Taking a second look at that page, the assumption is that the current package is CL-WHO which is kind of obvious but not obvious to a relative beginner to LISP!

(CL-WHO:with-html-output (*http-stream*)
(loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
("http://marcusmiller.com/" . "Marcus Miller")
("http://www.milesdavis.com/" . "Miles Davis"))
do (CL-WHO:htm (:a :href link
(:b (CL-WHO:str title)))
:br)))
The above code is the modified code as I fed it to my REPL in EMACS/SLIME mode and is the same as the above but you can see I just added the package name to it (uppercase for clarity). Like big deal but it made all the difference!

So, in that example and all others, if you ever get problems with undefined functions a good place to start is check the current package is what you expect / need it to be and take the correct corrective action.

Hope that helps somebody else.

Now, back to LISP before I start to forget stuff again. LOL :)

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.