From jan at rychter.com Wed Jun 3 09:06:20 2009 From: jan at rychter.com (Jan Rychter) Date: Wed, 03 Jun 2009 11:06:20 +0200 Subject: [cl-who-devel] str and esc inconsistency (suggestion) Message-ID: I have a suggestion for CL-WHO. Currently, you can't just replace str with esc in your code, because while str does a princ, esc expects a string. I have code that passes numbers to str and wanted to do a wholesale replacement. The manual says: str: Forms that look like (str form1 form*) will be substituted with (let ((result form1)) (when result (princ result s))) esc: Forms that look like (esc form1 form*) will be substituted with (let ((result form1)) (when result (write-string (escape-string result s)))). I would suggest improving esc by performing a princ if the first argument is not a string. --J. From edi at agharta.de Wed Jun 3 10:31:32 2009 From: edi at agharta.de (Edi Weitz) Date: Wed, 3 Jun 2009 12:31:32 +0200 Subject: [cl-who-devel] str and esc inconsistency (suggestion) In-Reply-To: References: Message-ID: Sounds good. Please send a patch against the dev version at bknr.net and I'll integrate this. http://bknr.net/trac/browser/trunk/thirdparty/cl-who http://weitz.de/patches.html Thanks, Edi. On Wed, Jun 3, 2009 at 11:06 AM, Jan Rychter wrote: > I have a suggestion for CL-WHO. > > Currently, you can't just replace str with esc in your code, because > while str does a princ, esc expects a string. I have code that passes > numbers to str and wanted to do a wholesale replacement. > > The manual says: > > str: Forms that look like (str form1 form*) will be substituted with (let > ((result form1)) (when result (princ result s))) > > esc: Forms that look like (esc form1 form*) will be substituted with (let > ((result form1)) (when result (write-string (escape-string result s)))). > > I would suggest improving esc by performing a princ if the first > argument is not a string. > > --J. > > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel > > From bryan.emrys at gmail.com Tue Jun 16 03:32:10 2009 From: bryan.emrys at gmail.com (Bryan Emrys) Date: Mon, 15 Jun 2009 20:32:10 -0700 Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right Message-ID: <200906152032.11206.bryan.emrys@gmail.com> Looking at the checkerboard-like example in the docs and trying to figure out how to get a table from a list of strings. Assume a list of 50 strings and I want to get them into a table that is 5 cells wide and 10 high. I can't seem to get the loop(s) right with the rows. I can do this without cl-who, but there should be an obvious method that I'm missing to be able to do this with cl-who. I apparently don't know enough loop-fu. Any pointers would be appreciated. Bryan From kengruven at gmail.com Tue Jun 16 06:49:07 2009 From: kengruven at gmail.com (Ken Harris) Date: Mon, 15 Jun 2009 23:49:07 -0700 Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right In-Reply-To: <200906152032.11206.bryan.emrys@gmail.com> References: <200906152032.11206.bryan.emrys@gmail.com> Message-ID: Hi Bryan, cl-who does have limitations, and one of them I've found is that it works best if you know a priori the structure you're generating. Putting items into a table in HTML, unfortunately, doesn't quite have this property. Still, you can certainly use it for that, especially if you don't mind nesting loops -- maybe something like: (defun gridify (x &optional (col 5)) ??"given a list of strings, put them in an html table (returned as a string) with |col| columns." ??(with-html-output-to-string (var nil) ?? ?(:table ?? ? (loop for xp on x by (lambda (p) (nthcdr col p)) do (htm (:tr (loop for i upto (1- col) for xi in xp do (htm (:td (str xi)))))))))) (gridify (loop for i from 1 upto 50 collect (format nil "cell #~D" i))) cheers, - Ken From sky at viridian-project.de Tue Jun 16 08:15:38 2009 From: sky at viridian-project.de (Leslie P. Polzer) Date: Tue, 16 Jun 2009 10:15:38 +0200 (CEST) Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right In-Reply-To: <200906152032.11206.bryan.emrys@gmail.com> References: <200906152032.11206.bryan.emrys@gmail.com> Message-ID: Bryan Emrys wrote: > Looking at the checkerboard-like example in the docs and trying to figure out how to get > a table from a list of strings. Assume a list of 50 strings and I want to get them into > a table that is 5 cells wide and 10 high. I can't seem to get the loop(s) right with the > rows. I can do this without cl-who, but there should be an obvious method that I'm > missing to be able to do this with cl-who. I apparently don't know enough loop-fu. Can you show your code and tell us what you're expecting it to do? Leslie -- http://www.linkedin.com/in/polzer From bryan.emrys at gmail.com Wed Jun 17 05:53:45 2009 From: bryan.emrys at gmail.com (Bryan Emrys) Date: Tue, 16 Jun 2009 22:53:45 -0700 Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right In-Reply-To: References: <200906152032.11206.bryan.emrys@gmail.com> Message-ID: <200906162253.45358.bryan.emrys@gmail.com> Now I'm really confused. Ken's example does exactly what I want when I create a gridify function and call it from a page macro (defmacro templates at the bottom of the email). But if I put the function body into the page macro, (see second example), it doesn't work. Rather, it prints the entire table, complete with tr and td with no string - then drops the list of strings after the table Both use exactly the same macros to generate the page and it is a cut and paste job. Somehow putting the function body into the macro is changing how the loops work: WORKS (defun gridify (x &optional (col 5)) "given a list of strings, put them in an html table (returned as a string) with |col| columns." (with-html-output-to-string (var nil) (:table (loop for xp on x by (lambda (p) (nthcdr col p)) do (htm (:tr (loop for i upto (1- col) for (id name) in xp do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name))))))))))) (defpage-easy-slp gridify-countries "Countries Grid" "/gridify-countries" () (let* ((data-query "select id,name from countries order by name ") (results (query data-query)) (col 5)) (gridify results col))) DOESNT WORK (defpage-easy-slp countries-grid "Countries Grid" "/countries-grid" () (let* ((data-query "select id,name from countries order by name ") (x (query data-query)) (col 5)) (with-html-output-to-string (var nil) (:table (loop for xp on x by (lambda (p) (nthcdr col p)) do (htm (:tr (loop for i upto (1- col) for (id name) in xp do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name)))))))))))) DEF MACROS (defmacro page-template (title &body body) `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) (:html (:head (:link :rel "stylesheet" :type "text/css" :href "/css/screen.css" :media "screen") (:title (str (format nil " ~a" ,title)))) (:body (:div :class "container" (:div :class "column span-24" (str , at body)))))))) (defmacro defpage-easy-slp (name title uri parameter-list &body body) `(define-easy-handler (,name :uri ,uri :default-request-type :both) ,parameter-list (page-template ,title , at body))) From info at jensteich.de Wed Jun 17 16:35:17 2009 From: info at jensteich.de (Jens Teich) Date: Wed, 17 Jun 2009 18:35:17 +0200 Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right In-Reply-To: <200906162253.45358.bryan.emrys@gmail.com> References: <200906152032.11206.bryan.emrys@gmail.com> <200906162253.45358.bryan.emrys@gmail.com> Message-ID: <4A391B45.9060602@jensteich.de> Bryan Emrys schrieb: > Now I'm really confused. Ken's example does exactly what I want when I create a gridify function and call it from a page macro (defmacro templates at the bottom of the email). But if I put the function body into the page macro, (see second example), it doesn't work. Rather, it prints the entire table, complete with tr and td with no string - then drops the list of strings after the table > Both use exactly the same macros to generate the page and it is a cut and paste job. Somehow putting the function body into the macro is changing how the loops work: > > WORKS > (defun gridify (x &optional (col 5)) > "given a list of strings, put them in an html table (returned as a string) with |col| columns." > (with-html-output-to-string (var nil) > (:table > (loop for xp on x by (lambda (p) (nthcdr col p)) > do (htm (:tr (loop for i upto (1- col) for (id name) in xp > do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name))))))))))) > > (defpage-easy-slp gridify-countries "Countries Grid" "/gridify-countries" () > (let* ((data-query "select id,name from countries order by name ") > (results (query data-query)) > (col 5)) > (gridify results col))) > > DOESNT WORK > > (defpage-easy-slp countries-grid "Countries Grid" "/countries-grid" () > (let* ((data-query "select id,name from countries order by name ") > (x (query data-query)) > (col 5)) > (with-html-output-to-string (var nil) > (:table > (loop for xp on x by (lambda (p) (nthcdr col p)) > do (htm (:tr (loop for i upto (1- col) for (id name) in xp > do (htm (:td (:a :href (format nil "~a~a" "countries-display?id=" id) (str name)))))))))))) > > DEF MACROS > > (defmacro page-template (title &body body) > `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) > (:html > (:head > (:link :rel "stylesheet" :type "text/css" :href "/css/screen.css" :media "screen") > (:title (str (format nil " ~a" ,title)))) > (:body > (:div :class "container" > (:div :class "column span-24" > (str , at body)))))))) > > (defmacro defpage-easy-slp (name title uri parameter-list &body body) > `(define-easy-handler (,name :uri ,uri > :default-request-type :both) > ,parameter-list > (page-template ,title , at body))) see http://lisp-univ-etc.blogspot.com/2009/03/cl-who-macros.html Jens From bryan.emrys at gmail.com Wed Jun 17 17:30:37 2009 From: bryan.emrys at gmail.com (Bryan Emrys) Date: Wed, 17 Jun 2009 10:30:37 -0700 Subject: [cl-who-devel] Building a table from a list of strings - Can't seem to get it right In-Reply-To: <4A391B45.9060602@jensteich.de> References: <200906152032.11206.bryan.emrys@gmail.com> <200906162253.45358.bryan.emrys@gmail.com> <4A391B45.9060602@jensteich.de> Message-ID: Ahh. Dawn begins to break over Marblehead. Thank you all. Bryan On Wed, Jun 17, 2009 at 9:35 AM, Jens Teich wrote: > Bryan Emrys schrieb: > > Now I'm really confused. Ken's example does exactly what I want when I > create a gridify function and call it from a page macro (defmacro templates > at the bottom of the email). But if I put the function body into the page > macro, (see second example), it doesn't work. Rather, it prints the entire > table, complete with tr and td with no string - then drops the list of > strings after the table > > Both use exactly the same macros to generate the page and it is a cut and > paste job. Somehow putting the function body into the macro is changing how > the loops work: > > > > WORKS > > (defun gridify (x &optional (col 5)) > > "given a list of strings, put them in an html table (returned as a > string) with |col| columns." > > (with-html-output-to-string (var nil) > > (:table > > (loop for xp on x by (lambda (p) (nthcdr col p)) > > do (htm (:tr (loop for i upto (1- col) for (id name) in xp > > do (htm (:td (:a :href (format nil "~a~a" > "countries-display?id=" id) (str name))))))))))) > > > > (defpage-easy-slp gridify-countries "Countries Grid" "/gridify-countries" > () > > (let* ((data-query "select id,name from countries order by name ") > > (results (query data-query)) > > (col 5)) > > (gridify results col))) > > > > DOESNT WORK > > > > (defpage-easy-slp countries-grid "Countries Grid" "/countries-grid" () > > (let* ((data-query "select id,name from countries order by name ") > > (x (query data-query)) > > (col 5)) > > (with-html-output-to-string (var nil) > > (:table > > (loop for xp on x by (lambda (p) (nthcdr col p)) > > do (htm (:tr (loop for i upto (1- col) for (id name) in xp > > do (htm (:td (:a :href (format nil "~a~a" > "countries-display?id=" id) (str name)))))))))))) > > > > DEF MACROS > > > > (defmacro page-template (title &body body) > > `(with-html-output-to-string (*standard-output* nil :prologue t > :indent t) > > (:html > > (:head > > (:link :rel "stylesheet" :type "text/css" :href "/css/screen.css" > :media "screen") > > (:title (str (format nil " ~a" ,title)))) > > (:body > > (:div :class "container" > > (:div :class "column span-24" > > (str , at body)))))))) > > > > (defmacro defpage-easy-slp (name title uri parameter-list &body body) > > `(define-easy-handler (,name :uri ,uri > > :default-request-type :both) > > ,parameter-list > > (page-template ,title , at body))) > > see http://lisp-univ-etc.blogspot.com/2009/03/cl-who-macros.html > > Jens > > > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: