[cl-who-devel] loop and with-html-output

Ron Garret ron at flownet.com
Thu Dec 22 18:38:43 UTC 2011


On Dec 22, 2011, at 9:19 AM, Tyler Smith wrote:

> On Thu, Dec 22, 2011 at 12:10 PM, Jeffrey Cunningham
> <jeffrey at jkcunningham.com> wrote:
>> On Thu, 22 Dec 2011 09:03:43 -0800, Tyler Smith
>> <tyler.smith at mail.mcgill.ca> wrote:
>> 
>>> On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant
>>> <sebyte at smolny.plus.com> wrote:
>>>> http://weitz.de/cl-who/#syntax
>>>> 
>>>> Hope this helps.
>>>> 
>>> 
>>> Not really, that's the documentation that I'm confused about. It
>>> starts out with the statement that strings will be printed verbatim.
>>> My variables are strings, but they aren't printed. I understand from
>>> Jens' response that I can get the function to work by wrapping my
>>> variables in (str ...), but I don't understand why that's necessary.
>>> The documentation of str suggests it's not necessary for strings:
>>> 
>>>   A form which is neither a string nor a keyword nor a list beginning
>>> with a keyword will be left as is except for the following
>>> substitutions:
>>> 
>>> My variables are already strings:
>>> 
>> 
>> Your variables are variables (symbols bound to addresses pointing to
>> strings), not strings.
>> 
>> --Jeff
> 
> Oh, I see. Is this a special circumstance of the macro then,

It's not a "special circumstance", it's what macros do.  The S-expressions that are arguments to macros are passed verbatim (that is, without being evaluated) to the macro expander function for that macro.  It gets confusing because one of the things that the macro expander can elect to do is to return that symbol as part of the macro expansion in a context where that symbol gets evaluated, so a symbol passed as an argument to a macro *might* become a variable reference, or it might not.

> or are
> symbols bound to strings and actual strings not interchangeable in
> Lisp?

Not in general, no.  They are interchangeable only in contexts where a form is being evaluated for its value.  That is a very common context, but there are others.

The case of WITH-HTML-OUTPUT is particularly confusing because it is a context where forms are evaluated, but NOT for their values.  W-H-O operates by side-effect (in particular, by outputting HTML to a stream), an NOT by computing a return value.  So when you write a literal string, W-H-O recognizes that and transforms it into a form that outputs that string to the HTML stream.  When you write a symbol, CL-WHO leaves it untouched.  So that symbol gets evaluated in the usual way, but then its value is discarded rather than output to the HTML stream.  The STR form is there to tell CL-WHO that you want the value of the variable to be output to the HTML stream.

Try this:

(pprint (macroexpand '(with-html-output (*standard-output*) (:b "foo") (:b x))))

The result will look hairy, but don't be intimidated.  Most of what you see is a MACROLET form that sets up some local macros.  The relevant part will be the last three lines at the end.

rg





More information about the Cl-who-devel mailing list