CL-WHO and a n00b gotcha!
Published by emacstheviking on Tue, 03/22/2011 - 18:24
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 :-
- You spelt it wrong.
- 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!
(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)))
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