This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
On Dec 16, 2009, at 5:20 AM, Phil Marneweck wrote:
This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
It has to do with format being passed nil: http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_format...
Chris.
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Ok I got some help in #lisp
I now have the following:
(defun recursive-test (count) (with-html-output (*standard-output*) (if (< count 10) (recursive-test (+ count 1)))
(str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" :default-request-type :both) () (with-html-output-to-string (*standard-output*) (recursive-test 0)))
Which gives me:
Recursive count- 10Recursive count- 9Recursive count- 8Recursive count- 7Recursive count- 6Recursive count- 5Recursive count- 4Recursive count- 3Recursive count- 2Recursive count- 1Recursive count- 0Recursive count- 0
Why do I get 2 Recursive count- 0?
Is this hunchentoot or am I not understanding recursion in lisp?
On Wed, 2009-12-16 at 13:20 +0200, Phil Marneweck wrote:
This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Just a correction this code is the code that actually created the Recursive count- 0 and not the previous code...the previous code is actualy the code that gives the correct output
(defun recursive-test (count) (with-html-output (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" :default-request-type :both) () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
On Wed, 2009-12-16 at 14:03 +0200, Phil Marneweck wrote:
Ok I got some help in #lisp
I now have the following:
(defun recursive-test (count) (with-html-output (*standard-output*) (if (< count 10) (recursive-test (+ count 1)))
(str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" :default-request-type :both) () (with-html-output-to-string (*standard-output*) (recursive-test 0)))
Which gives me:
Recursive count- 10Recursive count- 9Recursive count- 8Recursive count- 7Recursive count- 6Recursive count- 5Recursive count- 4Recursive count- 3Recursive count- 2Recursive count- 1Recursive count- 0Recursive count- 0
Why do I get 2 Recursive count- 0?
Is this hunchentoot or am I not understanding recursion in lisp?
On Wed, 2009-12-16 at 13:20 +0200, Phil Marneweck wrote:
This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Phil Marneweck wrote:
This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
This might be more of an issue with your understanding of CL-WHO rather than Lisp ;)
(defun recursive-test (count) (with-html-output (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A~%" count))))
Note that I am using WITH-HTML-OUTPUT instead of WITH-HTML-OUTPUT-TO-STRING. This way, output by all recursive calls would go to *standard-output* which is then be handled by TEST-RECURSIVE.
(define-easy-handler (test-recursive :uri "/test.html") () (with-html-output-to-string (*standard-output*) (recursive-test 0)))
We don't need the (STR ...) around (RECURSIVE-TEST 0) since we are not interested in the return value. Also, you don't necessarily need to use WITH-HTML-OUTPUT-TO-STRING here -- even WITH-OUTPUT-TO-STRING would work.
Chaitanya
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel
Thanx I got the same answer on #lisp
For some reason I only received this mail an hour after you actually sent it, thus my latter posts...appologize to the group as a whole for that. I was not ignoring answers on the mailing list I just did not get them until to late.
On Wed, 2009-12-16 at 17:34 +0530, Chaitanya Gupta wrote:
Phil Marneweck wrote:
This is most likely a problem with my understanding of lisp and not hunchnetoot.
Why does the following function only out put "Recursive count- 0" to the hunchentoot page?
This might be more of an issue with your understanding of CL-WHO rather than Lisp ;)
(defun recursive-test (count) (with-html-output (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A~%" count))))
Note that I am using WITH-HTML-OUTPUT instead of WITH-HTML-OUTPUT-TO-STRING. This way, output by all recursive calls would go to *standard-output* which is then be handled by TEST-RECURSIVE.
(define-easy-handler (test-recursive :uri "/test.html") () (with-html-output-to-string (*standard-output*) (recursive-test 0)))
We don't need the (STR ...) around (RECURSIVE-TEST 0) since we are not interested in the return value. Also, you don't necessarily need to use WITH-HTML-OUTPUT-TO-STRING here -- even WITH-OUTPUT-TO-STRING would work.
Chaitanya
(defun recursive-test (count) (with-html-output-to-string (*standard-output*) (if (< count 10) (recursive-test (+ count 1))) (str (format nil "Recursive count- ~A" count))))
(define-easy-handler (test-recursive :uri "/test.html" () (with-html-output-to-string (*standard-output*) (str (recursive-test 0))))
tbnl-devel site list tbnl-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/tbnl-devel