From: James
Subject: newbie question
Date: 
Message-ID: <89daabb7-3c79-4a2c-a506-28e9e52fef40@m16g2000vbp.googlegroups.com>
I've banged my head against the wall on this for the past couple of
days, and haven't been able to figure it out.  I know it's a newb
question, but hey - I'm a newb.  I'm working with hunchentoot and cl-
who, working on a modified, webified version of the PCL cd library -
pushing message posts onto a list instead of cds.  My problem comes
from a misunderstanding or a failure to understand macros in some way
(I think).  When I try to run the following code, hunchentoot throws
back a 500 error.

(defun display-message ()
  (cl-who:with-html-output-to-string (*+html-stream+*)
    (:html
     (:head (:title "Show a single message"))
     (:body
      (:div
       (let ((msgid (hunchentoot:get-parameter "message")))
	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
(where :message-id msgid))) 'subject))))))))


If I replace the last msgid with a number, it works fine.  I know it's
something I'm missing with macros, but I can't figure it out on my -
any pointers?

From: Volkan YAZICI
Subject: Re: newbie question
Date: 
Message-ID: <e31da2e9-655f-448d-b99b-1de737082789@r37g2000prr.googlegroups.com>
On Jan 1, 7:45 pm, James <···········@gmail.com> wrote:
> (defun display-message ()
>   (cl-who:with-html-output-to-string (*+html-stream+*)
>     (:html
>      (:head (:title "Show a single message"))
>      (:body
>       (:div
>        (let ((msgid (hunchentoot:get-parameter "message")))
>          (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
> (where :message-id msgid))) 'subject))))))))

If you'd check TREE-TO-COMMANDS in who.lisp, it writes that:

  ;; (FMT form*) --> (FORMAT STREAM
form*)
  (list* 'format stream (rest x)))))

Namely, there is nothing magical about FMT directive of CL-WHO. For
debugging, you can try partially expanding CL-WHO macros step by step.
(For this purpose, C-c C-m and C-c M-m keys can help you in SLIME.)


Regards.
From: Tamas K Papp
Subject: Re: newbie question
Date: 
Message-ID: <6s4e9eF3vmasU2@mid.individual.net>
On Thu, 01 Jan 2009 09:45:57 -0800, James wrote:

> I've banged my head against the wall on this for the past couple of
> days, and haven't been able to figure it out.  I know it's a newb
> question, but hey - I'm a newb.  I'm working with hunchentoot and cl-
> who, working on a modified, webified version of the PCL cd library -
> pushing message posts onto a list instead of cds.  My problem comes from
> a misunderstanding or a failure to understand macros in some way (I
> think).  When I try to run the following code, hunchentoot throws back a
> 500 error.
> 
> (defun display-message ()
>   (cl-who:with-html-output-to-string (*+html-stream+*)
>     (:html
>      (:head (:title "Show a single message")) (:body
>       (:div
>        (let ((msgid (hunchentoot:get-parameter "message")))
> 	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
> (where :message-id msgid))) 'subject))))))))
> 
> 
> If I replace the last msgid with a number, it works fine.  I know it's
> something I'm missing with macros, but I can't figure it out on my - any
> pointers?

I know little about the context of this, but I would first check that 
msgid inside that let is what you want it to be, eg insert

(format t "msgid: ~a~%")

etc.

Tamas
From: James
Subject: Re: newbie question
Date: 
Message-ID: <4f53ca04-362b-4c49-a15b-4cb9480bc3e2@r27g2000vbp.googlegroups.com>
If I replace msgid inside the 'where' call with a number (not a
variable), the output is correct.If I do the following, the output is
correct:

(defun display-message ()
  (cl-who:with-html-output-to-string (*+html-stream+*)
    (:html
     (:head (:title "Show a single message"))
     (:body
      (:div
       (let ((msgid (hunchentoot:get-parameter "message")))
	 (cl-who:fmt "Message requested: ~A" msgid)))))))
;;	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
(where :message-id msgid))) 'subject))))))))


> I know little about the context of this, but I would first check that
> msgid inside that let is what you want it to be, eg insert
>
> (format t "msgid: ~a~%")
>
> etc.
>
> Tamas
From: Don Geddis
Subject: Re: newbie question
Date: 
Message-ID: <87vdsy4uxa.fsf@geddis.org>
James <···········@gmail.com> wrote on Thu, 1 Jan 2009 :
> If I replace msgid inside the 'where' call with a number (not a
> variable), the output is correct.If I do the following, the output is
> correct:
>        (let ((msgid (hunchentoot:get-parameter "message")))

Are you sure that get-parameter returns a number?

> 	 (cl-who:fmt "Message requested: ~A" msgid)))))))

Try "~S" instead of "~A" in the format.

> ;;	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
> (where :message-id msgid))) 'subject))))))))

Also start backing up to the next level.  Print out the result of
        (where :message-id msgid)
instead of just msgid itself.

        -- Don
_______________________________________________________________________________
Don Geddis                  http://don.geddis.org/               ···@geddis.org
All brontosauruses are thin at one end, much MUCH thicker in the middle,
and then thin again at the far end.
	-- New dinosaur theory by "Miss Anne Elk" (Monty Python)
From: Pascal J. Bourguignon
Subject: Re: newbie question
Date: 
Message-ID: <87zliakcqq.fsf@informatimago.com>
James <···········@gmail.com> writes:

> If I replace msgid inside the 'where' call with a number (not a
> variable), the output is correct.If I do the following, the output is
> correct:
>
> (defun display-message ()
>   (cl-who:with-html-output-to-string (*+html-stream+*)
>     (:html
>      (:head (:title "Show a single message"))
>      (:body
>       (:div
>        (let ((msgid (hunchentoot:get-parameter "message")))
> 	 (cl-who:fmt "Message requested: ~A" msgid)))))))
> ;;	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select (where :message-id msgid))) 'subject))))))))

Therefore problem is not with cl-who but with the (select (where ...))
form.  I don't know what they are.  Are you sure you can give a variable
to WHERE?  What do you get if you type at the REPL something like:

(let ((msgid "some-id"))
   (select (where :message-id msgid)))

?


-- 
__Pascal Bourguignon__
From: Kenneth Tilton
Subject: Re: newbie question
Date: 
Message-ID: <495d4f9b$0$20286$607ed4bc@cv.net>
Tamas K Papp wrote:
> On Thu, 01 Jan 2009 09:45:57 -0800, James wrote:
> 
>> I've banged my head against the wall on this for the past couple of
>> days, and haven't been able to figure it out.  I know it's a newb
>> question, but hey - I'm a newb.  I'm working with hunchentoot and cl-
>> who, working on a modified, webified version of the PCL cd library -
>> pushing message posts onto a list instead of cds.  My problem comes from
>> a misunderstanding or a failure to understand macros in some way (I
>> think).  When I try to run the following code, hunchentoot throws back a
>> 500 error.
>>
>> (defun display-message ()
>>   (cl-who:with-html-output-to-string (*+html-stream+*)
>>     (:html
>>      (:head (:title "Show a single message")) (:body
>>       (:div
>>        (let ((msgid (hunchentoot:get-parameter "message")))
>> 	 (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
>> (where :message-id msgid))) 'subject))))))))
>>
>>
>> If I replace the last msgid with a number, it works fine.  I know it's
>> something I'm missing with macros, but I can't figure it out on my - any
>> pointers?

OP: Apparently uou know more than Tamas.

> 
> I know little about the context of this, but I would first check that 
> msgid inside that let is what you want it to be, eg insert
> 
> (format t "msgid: ~a~%")

TP: For the love of god, man, can you read?* He substituted the literal 
value and got what he wanted and cleverly grokked it was a macrology issue.

 From PCL: the definition of where:

(defmacro where (&rest clauses)
   `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))

OP: I want you to eat for the rest of your life, so please hack up where 
and make-comparison-lists to print out the value of their inputs, and 
then /compile/ (not run) display-message.

You can also just:(macroexpand '(where :msgid hi-mom)) I changed to 
'hi-mom to reduce distractions.

Now meditate on your navel.

The issue is, with any given macro, when are the input forms evaluated? 
If an input form is not evaluated at run-time (ie, if the form itself 
gets processed at compile-time) you are doomed trying to use anything 
other than a literal value (whose form, ny def, evaluates to itself).

"doomed", btw, means you are looking for some other tool that /does/ 
evaluate its input, possibly called select-query (I made that up). Then 
you would do:

    (select-query '(where :msgid 42)

...which is silly because 42 already works with select, or:

    (select-query `(where :msgid ,hi-mom))

Left as an exercise: where-query, so you can (let's abrreviate, k?):

    (select (whereq :msgid hi-mom))

hth, kzo
From: Kenneth Tilton
Subject: Re: newbie question
Date: 
Message-ID: <495d5833$0$14293$607ed4bc@cv.net>
Kenneth Tilton wrote:
> Tamas K Papp wrote:
>> On Thu, 01 Jan 2009 09:45:57 -0800, James wrote:
>>
>>> I've banged my head against the wall on this for the past couple of
>>> days, and haven't been able to figure it out.  I know it's a newb
>>> question, but hey - I'm a newb.  I'm working with hunchentoot and cl-
>>> who, working on a modified, webified version of the PCL cd library -
>>> pushing message posts onto a list instead of cds.  My problem comes from
>>> a misunderstanding or a failure to understand macros in some way (I
>>> think).  When I try to run the following code, hunchentoot throws back a
>>> 500 error.
>>>
>>> (defun display-message ()
>>>   (cl-who:with-html-output-to-string (*+html-stream+*)
>>>     (:html
>>>      (:head (:title "Show a single message")) (:body
>>>       (:div
>>>        (let ((msgid (hunchentoot:get-parameter "message")))
>>>      (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car (select
>>> (where :message-id msgid))) 'subject))))))))
>>>
>>>
>>> If I replace the last msgid with a number, it works fine.  I know it's
>>> something I'm missing with macros, but I can't figure it out on my - any
>>> pointers?
> 
> OP: Apparently uou know more than Tamas.
> 
>>
>> I know little about the context of this, but I would first check that 
>> msgid inside that let is what you want it to be, eg insert
>>
>> (format t "msgid: ~a~%")
> 
> TP: For the love of god, man, can you read?* He substituted the literal 
> value and got what he wanted and cleverly grokked it was a macrology issue.
> 
>  From PCL: the definition of where:
> 
> (defmacro where (&rest clauses)
>   `#'(lambda (cd) (and ,@(make-comparisons-list clauses))))
> 
> OP: I want you to eat for the rest of your life, so please hack up where 
> and make-comparison-lists to print out the value of their inputs, and 
> then /compile/ (not run) display-message.
> 
> You can also just:(macroexpand '(where :msgid hi-mom)) I changed to 
> 'hi-mom to reduce distractions.
> 
> Now meditate on your navel.
> 
> The issue is, with any given macro, when are the input forms evaluated? 
> If an input form is not evaluated at run-time (ie, if the form itself 
> gets processed at compile-time) you are doomed trying to use anything 
> other than a literal value (whose form, ny def, evaluates to itself).
> 
> "doomed", btw, means you are looking for some other tool that /does/ 
> evaluate its input, possibly called select-query (I made that up). Then 
> you would do:
> 
>    (select-query '(where :msgid 42)

Oops, here and in the next bit (now deleted) I forgot that the issue 
turned out to be with "where", not select, select being a normal 
function. ie, Yeah, I am just typing over the keyboard.

Rather than try to salvage this mess, let's just leave it at your goal 
being (and let's drive home the point):

      (select (where-query :msg-id
                   (hunchentoot:get-parameter "message")))

..and then something like:

      (let ((id (hunchentoot:get-parameter "message")))
         (select (whereq :msgid id)))

...where the /function/ where-query is a modification of PCL's 'where' 
macro and 'whereq let's you buy back the syntactic brevity. That sould 
get interesting if one wants to limit evaluation to the value form and 
not the key, by which I mean this would /not/ work:

      (let ((key :msgid)
            (id (hunchentoot:get-parameter "message")))
         (select (whereq key id))

still just typing at keyboard,k
From: James
Subject: Re: newbie question
Date: 
Message-ID: <93316a32-f1a6-4bba-803b-64d482e94106@v15g2000vbb.googlegroups.com>
Here's the original function, and the defuns for the select & where
(they are not macros).  I'm thinking that it has something to do with
the cl-who:w-h-o-t-s macro, and the way it's interacting with the two
defun's and lambda:


(defun where (&key topic subject message-id parentid)
  #'(lambda (msg)
      (and
       (if topic (equal (slot-value msg 'topic) topic ) t)
       (if subject (equal (slot-value msg 'subject) subject) t)
       (if message-id (equal (slot-value msg 'message-id) message-id)
t)
       (if parentid (equal (slot-value msg 'parent-message-id)
parentid) t))))

(defun select (selector-fn)
  (remove-if-not selector-fn *message-list*))


(defun display-message ()
   (cl-who:with-html-output-to-string (*+html-stream+*)
     (:html
      (:head (:title "Show a single message")) (:body
       (:div
        (let ((msgid (hunchentoot:get-parameter "message")))
      (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car
(select
 (where :message-id msgid))) 'subject))))))))
From: Kenneth Tilton
Subject: Re: newbie question
Date: 
Message-ID: <495da17b$0$14307$607ed4bc@cv.net>
James wrote:
> Here's the original function, and the defuns for the select & where
> (they are not macros).  

F*ck, now I owe Tamas an apology! 2009 is off to a great start.

> I'm thinking that it has something to do with
> the cl-who:w-h-o-t-s macro, and the way it's interacting with the two
> defun's and lambda:
> 
> 
> (defun where (&key topic subject message-id parentid)
>   #'(lambda (msg)
>       (and
>        (if topic (equal (slot-value msg 'topic) topic ) t)
>        (if subject (equal (slot-value msg 'subject) subject) t)
>        (if message-id (equal (slot-value msg 'message-id) message-id)
> t)
>        (if parentid (equal (slot-value msg 'parent-message-id)
> parentid) t))))
> 
> (defun select (selector-fn)
>   (remove-if-not selector-fn *message-list*))
> 
> 
> (defun display-message ()
>    (cl-who:with-html-output-to-string (*+html-stream+*)
>      (:html
>       (:head (:title "Show a single message")) (:body
>        (:div
>         (let ((msgid (hunchentoot:get-parameter "message")))

Right here ^^^ might be your problem. cl-who does its own form of macro 
expansion and IIUC has no case to handle "Let". ie, it has things like 
:head and :div and even fmt, so you have to lead with those. But once it 
gets to (fmt this that the other thing) it just bungs in everything 
after the fmt into a format statement, so you can do your let statement 
just in time (and be grateful Lisp subsumes the functionale).

See below for a quickly edited untested possibility.

>       (cl-who:fmt "Slot value of 'subject: ~A" (slot-value (car
> (select
>  (where :message-id msgid))) 'subject))))))))


(defun display-message ()
   (cl-who:with-html-output-to-string (*+html-stream+*)
     (:html
      (:head (:title "Show a single message"))
      (:body
       (:div
        (cl-who:fmt "Slot value of 'subject: ~A"
          (let ((msgid (hunchentoot:get-parameter "message")))
            (slot-value (car
                         (select
                          (where :message-id msgid))) 'subject))))))))

hth,kt
From: Tamas K Papp
Subject: Re: newbie question
Date: 
Message-ID: <6s52fbF494prU1@mid.individual.net>
On Thu, 01 Jan 2009 18:19:31 -0500, Kenneth Tilton wrote:

> Tamas K Papp wrote:
>> I know little about the context of this, but I would first check that
>> msgid inside that let is what you want it to be, eg insert
>> 
>> (format t "msgid: ~a~%")
> 
> TP: For the love of god, man, can you read?* He substituted the literal
> value and got what he wanted and cleverly grokked it was a macrology
> issue.

The OP didn't post the macro, and it is surely not standard.  A macro
can behave differently depending on whether it is passed literal
values or symbols (though that is not something I would usually design
when writing simple macros, but I don't know the example in question).

Generally people can get better help if they post all relevant code.
You did look it up instead of the OP, which is nice of you, but can't
be generally expected.

Tamas