Good news
To save on emailing, I'm going to use this forum to announce my latest good news. As some of you have heard, I've taken up
the internship I mentioned. I'll be spending three months this summer in sunny California, implementing Semantic Web stuff in Lisp for Tellme Networks. It's a very exciting opportunity, and I'm sure I'll get a lot out of it (and I think Tellme have the same perspective on things).
Now I'm sorting out visas and shuttling paper around….
Any recommendations, thoughts, opinions,
etc. about Mountain View, California, whether to go for an apartment or a shared house, what to do about mobile phones, or internships in general are
very welcome — it's all new to me!
At this point I really wish I'd implemented comments on this blog!
Posted at 2005-04-27 11:12:14 by Richard • Link to Good news
, trackbacks.
CL-WHO and dynamically-constructed pages
CL-WHO is a neat little library for doing HTML generation in Lisp. It expands an expression into an efficient series of calls to
write-string and
princ that, when called, will produce the appropriate XHTML on the output stream. Unfortunately, this only works on lists that are present when the macro is expanded. You can do this:
(with-html-output-to-string (s) (:div "Hello"))
but not this:
(defun list-maker () (list ':div "Hello"))
(with-html-output-to-string (s) (list-maker))
(The reason, of course, is that the macro that does the work doesn't evaluate its input.)
This is a real inconvenience if you want to programmatically build Web pages; each function that might be composited has to produce its output as a string to be built into other CL-WHO expressions. I want to build pages programmatically, constructing a CL-WHO expression and then processing it into a string. Don't ask why.
Now, you could wrap a call to the macro in
eval, but that's bad form and very, very slow. You could also write a function that works with the output of the macroexpansion, running the calls —
i.e. implementing
eval. The right thing to do, in my opinion, is to write a tree-walking function or two that replicate the work done by the normal operation of the library, but directly output strings.
Which is exactly what I did this afternoon.
I've hacked up
tree-to-commands and its supporting code to write output directly to a stream as the tree is parsed. The new exported function is named
tree-to-stream, and
(tree-to-stream (list-maker) *standard-output*)
will do exactly what one would expect: print
<div>Hello</div> to the console.
It's now possible to use the CL-WHO HTML representation as an alternative to HTML strings, and blat them out to a stream when you're done. If that's not a perversion of the whole point of the library, I don't know what is!
However, on the off chance that it's useful to someone else,
here's the code. It's BSD-licensed, just like the original. My apologies to
Edi Weitz for turning his elegant library to the dark side!
Posted at 2005-04-27 11:03:26 by Richard • Link to CL-WHO and dynamic…
, trackbacks.