[hunchentoot-devel] resurrect tbnl's debug-value macro?
Mac Chan
emailmac at gmail.com
Fri May 4 04:02:21 UTC 2007
Hi Pierre,
On 5/3/07, Pierre THIERRY <nowhere.man at levallois.eu.org> wrote:
> You're right. I thought about it and the solution seemed too simple for
> me not to try and code it cleanly. I've published the code under MIT
> license here (that's a Mercurial repository):
>
> Basically, you'd use leak-variables as needed in a handler, and it would
> store variables along with their names, so you can bind them to use them
> later with with-leaked-variables:
>
> (define-leak-variable *leak*)
>
> (defun handler-to-debug ()
> (leak-variables *leak* *request* *reply* *session*)
> (do-some-hairy-stuff))
>
> (with-leaked-variables *leak*
> (handler-to-debug))
I don't want to keep going back to this topic but I find it
strange that you don't follow what my intention was because I
thought that's how everyone else write lisp code in a bottom up
style (paraphrase PG).
So using my previous toy example:
These are my sexp building blocks:
(session-value :selected-product)
(session-value :quantity)
(product-price (session-value :selected-product))
(* (session-value :quantity) (product-price (session-value :selected-product)))
What I want is to type these expressions in the REPL or in a
buffer, eval them and check the results. If they work fine, I can
put them together like LEGO and wrap them around a defun.
Now the problem is the dynamically bound variables.
Using your macro, my work flow would be:
(with-leaked-variables *leak*
(session-value :selected-product))
(with-leaked-variables *leak*
(session-value :quantity))
and then if they work, I need to cut the inner sexp and paste it
into the defun, how inconvenient!
What's more, that's not even the way that I prefer to write code.
Instead, I code up a defun that is not necessary working but then
I can test each of the inner sexps interactively.
(defun product-total-page (&optional (request *request*))
(let ((p (session-value :selected-product)_1)
(q (session-value :quantity)_2))
(with-html
(:html
(:body
(:table
(:tr (:td "Product") (:td (str p)))
(:tr (:td "Quantity") (:td (str q)))
(:tr (:td "Total") (:td (str (* q (product-price p))))))))))_3)
What I do is that I place the cursor at the end of a sexp (marked
by _) that I want to test and send it to slime with c-x c-e
;; c-x c-e with cursor at _1
;; emacs message buffer shows
"T-Shirt XXL"
;; c-x c-e with cursor at _2
10
;; c-x c-e with cursor at _3
"<html><body>....</body></html>"
;; eval the following in the REPL
> (product-total-page)
=> "<html><body>....</body></html>"
The above example has no errors , but you can imagine that it
_evolves_ from a broken state to the working code.
Now if you require me to wrap every sexp with your
(with-leaked-variables) macro before I can test them, I think
I'll just give up and go back to perl or python or whatever (they
have libraries covering everything you want to write BTW ;-)
Regards,
-- Mac
(PS: Have you seen Marco Baringer's slime video?)
More information about the Tbnl-devel
mailing list