From tyler.smith at mail.mcgill.ca Wed Dec 21 22:16:28 2011 From: tyler.smith at mail.mcgill.ca (Tyler Smith) Date: Wed, 21 Dec 2011 17:16:28 -0500 Subject: [cl-who-devel] loop and with-html-output Message-ID: Hi, I'm new to lisp in general, trying to get cl-sql and cl-who working together. I'm stumped in my efforts to generate a definition list from an sql query. The following works as expected: (multiple-value-bind (records fields) (select [genus] [species] :from "specimens" :where [= [collector] "Test"]) (loop for rec in records do (loop for label in fields for val in rec do (fresh-line) (print label) (print val)))) => "GENUS" "Scleria" "SPECIES" "triglomerata" However, swapping print for with-output-to-html fails: * (multiple-value-bind (records fields) (select [genus] [species] :from "specimens" :where [= [collector] "Test"]) (loop for rec in records do (loop for label in fields for val in rec do (fresh-line) (with-html-output (*standard-output* nil :indent nil) (:dt label) (:dd val)))))
What have I missed? Any other suggestions for doing this in a lispier way would also be welcome. Thanks, Tyler From info at jensteich.de Thu Dec 22 06:56:40 2011 From: info at jensteich.de (Jens Teich) Date: Thu, 22 Dec 2011 07:56:40 +0100 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: Message-ID: <4EF2D4A8.80907@jensteich.de> > * (multiple-value-bind (records fields) > (select [genus] [species] :from "specimens" :where [= [collector] "Test"]) > (loop for rec in records do > (loop for label in fields > for val in rec do > (fresh-line) > (with-html-output (*standard-output* nil :indent nil) > (:dt label) > (:dd val))))) > (:dt (str label)) (:dd (str val)) -jens From sebyte at smolny.plus.com Thu Dec 22 15:53:59 2011 From: sebyte at smolny.plus.com (Sebastian Tennant) Date: Thu, 22 Dec 2011 15:53:59 +0000 Subject: [cl-who-devel] loop and with-html-output References: Message-ID: http://weitz.de/cl-who/#syntax Hope this helps. Sebastian -- Emacs' AlsaPlayer - Music Without Jolts Lightweight, full-featured and mindful of your idyllic happiness. http://home.gna.org/eap From tyler.smith at mail.mcgill.ca Thu Dec 22 17:03:43 2011 From: tyler.smith at mail.mcgill.ca (Tyler Smith) Date: Thu, 22 Dec 2011 12:03:43 -0500 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> Message-ID: On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant 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: * (multiple-value-bind (records fields) (select [genus] [species] :from "specimens" :where [< [specimen_id] 4]) (loop for rec in records do (loop for label in fields for val in rec do (fresh-line) (princ (stringp label)) (princ (stringp val))))) TT TT TT TT TT TT NIL * Can someone explain why my variables aren't being treated as strings within with-html-output? The definition of (str ...) continues: Forms that look like (str form1 form*) will be substituted with (let ((result form1)) (when result (princ result s))). I'm new to Lisp (as must be clear by now!): what is the difference between (princ form1) and (let ((result form1)) (princ result)) Thanks for your help, Tyler From jeffrey at jkcunningham.com Thu Dec 22 17:10:07 2011 From: jeffrey at jkcunningham.com (Jeffrey Cunningham) Date: Thu, 22 Dec 2011 09:10:07 -0800 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> Message-ID: On Thu, 22 Dec 2011 09:03:43 -0800, Tyler Smith wrote: > On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant > 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 From edi at agharta.de Thu Dec 22 17:12:27 2011 From: edi at agharta.de (Edi Weitz) Date: Thu, 22 Dec 2011 18:12:27 +0100 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> Message-ID: In your example, LABEL is not a string. It's a symbol that happens to be bound to a string. A string is something that starts and ends with double quotes. Note that, as the documentation says, WITH-OUTPUT-TO-STRING is a macro. It has no way to look into the future and to know what value the variable LABEL will have at a specific point in time... :) Cheers, Edi. On Thu, Dec 22, 2011 at 6:03 PM, Tyler Smith wrote: > On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant > 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: > > * (multiple-value-bind (records fields) > ? ?(select [genus] [species] :from "specimens" :where [< [specimen_id] 4]) > ?(loop for rec in records do > ? ? ? (loop for label in fields > ? ? ? ? ?for val in rec do > ? ? ? ? ? ?(fresh-line) > ? ? ? ? ? ?(princ (stringp label)) > ? ? ? ? ? ?(princ (stringp val))))) > > > TT > TT > TT > TT > TT > TT > NIL > * > > Can someone explain why my variables aren't being treated as strings > within with-html-output? > > The definition of (str ...) continues: > > ?Forms that look like (str form1 form*) will be substituted with (let > ((result form1)) (when result (princ result s))). > > I'm new to Lisp (as must be clear by now!): what is the difference between > > ?(princ form1) > > and > > ?(let ((result form1)) > ? ?(princ result)) > > Thanks for your help, > > Tyler > > _______________________________________________ > cl-who-devel site list > cl-who-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-who-devel > From tyler.smith at mail.mcgill.ca Thu Dec 22 17:19:25 2011 From: tyler.smith at mail.mcgill.ca (Tyler Smith) Date: Thu, 22 Dec 2011 12:19:25 -0500 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> Message-ID: On Thu, Dec 22, 2011 at 12:10 PM, Jeffrey Cunningham wrote: > On Thu, 22 Dec 2011 09:03:43 -0800, Tyler Smith > wrote: > >> On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant >> 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, or are symbols bound to strings and actual strings not interchangeable in Lisp? Thanks for your patience, Tyler From edi at agharta.de Thu Dec 22 17:30:11 2011 From: edi at agharta.de (Edi Weitz) Date: Thu, 22 Dec 2011 18:30:11 +0100 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> Message-ID: On Thu, Dec 22, 2011 at 6:19 PM, Tyler Smith wrote: > Oh, I see. Is this a special circumstance of the macro then, or are > symbols bound to strings and actual strings not interchangeable in > Lisp? See my previous reply. There's nothing specific about Lisp here. The concept you'll want to look up is "literal". From tyler.smith at mail.mcgill.ca Thu Dec 22 18:21:49 2011 From: tyler.smith at mail.mcgill.ca (Tyler Smith) Date: Thu, 22 Dec 2011 13:21:49 -0500 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: <24420_1324575096_4EF36978_24420_177_1_7a6a03ff196747638de37d0db57d1caa@EXHUB2010-1.campus.MCGILL.CA> References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> <24420_1324575096_4EF36978_24420_177_1_7a6a03ff196747638de37d0db57d1caa@EXHUB2010-1.campus.MCGILL.CA> Message-ID: On Thu, Dec 22, 2011 at 12:30 PM, Edi Weitz wrote: > On Thu, Dec 22, 2011 at 6:19 PM, Tyler Smith wrote: > >> Oh, I see. Is this a special circumstance of the macro then, or are >> symbols bound to strings and actual strings not interchangeable in >> Lisp? > > See my previous reply. > > There's nothing specific about Lisp here. ?The concept you'll want to > look up is "literal". > Ok, I think I have a general understanding. I have to spend some more time on macros and the distinction between run-time and compile time. Thanks for your help, Tyler From vseloved at gmail.com Thu Dec 22 18:43:16 2011 From: vseloved at gmail.com (Vsevolod Dyomkin) Date: Thu, 22 Dec 2011 21:43:16 +0300 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> <24420_1324575096_4EF36978_24420_177_1_7a6a03ff196747638de37d0db57d1caa@EXHUB2010-1.campus.MCGILL.CA> Message-ID: Also if you want to use macros with CL-WHO, you might want to check http://lisp-univ-etc.blogspot.com/2009/03/cl-who-macros.html Best, Vsevolod On Thu, Dec 22, 2011 at 9:21 PM, Tyler Smith wrote: > On Thu, Dec 22, 2011 at 12:30 PM, Edi Weitz wrote: > > On Thu, Dec 22, 2011 at 6:19 PM, Tyler Smith > wrote: > > > >> Oh, I see. Is this a special circumstance of the macro then, or are > >> symbols bound to strings and actual strings not interchangeable in > >> Lisp? > > > > See my previous reply. > > > > There's nothing specific about Lisp here. The concept you'll want to > > look up is "literal". > > > > Ok, I think I have a general understanding. I have to spend some more > time on macros and the distinction between run-time and compile time. > > Thanks for your help, > > Tyler > > _______________________________________________ > 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: From ron at flownet.com Thu Dec 22 18:38:43 2011 From: ron at flownet.com (Ron Garret) Date: Thu, 22 Dec 2011 10:38:43 -0800 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> Message-ID: <3B2EDFEC-146B-4CEA-BDAC-D96F63EFF430@flownet.com> On Dec 22, 2011, at 9:19 AM, Tyler Smith wrote: > On Thu, Dec 22, 2011 at 12:10 PM, Jeffrey Cunningham > wrote: >> On Thu, 22 Dec 2011 09:03:43 -0800, Tyler Smith >> wrote: >> >>> On Thu, Dec 22, 2011 at 10:53 AM, Sebastian Tennant >>> 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 From edi at agharta.de Thu Dec 22 19:40:47 2011 From: edi at agharta.de (Edi Weitz) Date: Thu, 22 Dec 2011 20:40:47 +0100 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: <3B2EDFEC-146B-4CEA-BDAC-D96F63EFF430@flownet.com> References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> <3B2EDFEC-146B-4CEA-BDAC-D96F63EFF430@flownet.com> Message-ID: On Thu, Dec 22, 2011 at 7:38 PM, Ron Garret wrote: > Try this: > > (pprint (macroexpand '(with-html-output (*standard-output*) (:b "foo") (:b x)))) http://weitz.de/cl-who/#show-html-expansion From tyler.smith at mail.mcgill.ca Thu Dec 22 22:04:46 2011 From: tyler.smith at mail.mcgill.ca (Tyler Smith) Date: Thu, 22 Dec 2011 17:04:46 -0500 Subject: [cl-who-devel] loop and with-html-output In-Reply-To: <18512_1324579135_4EF3793E_18512_84_2_1fcff5dc09aa4692aadd9d6532701269@EXHUB2010-1.campus.MCGILL.CA> References: <15833_1324570251_4EF3568B_15833_15_1_eb9bfa889670444e9fd1910d16763ad6@EXHUB2010-2.campus.MCGILL.CA> <23968_1324573857_4EF364A1_23968_56_1_b1d6e5d2d33047cb8fd7e53d8189b16a@EXHUB2010-3.campus.MCGILL.CA> <18512_1324579135_4EF3793E_18512_84_2_1fcff5dc09aa4692aadd9d6532701269@EXHUB2010-1.campus.MCGILL.CA> Message-ID: On Thu, Dec 22, 2011 at 1:38 PM, Ron Garret wrote: > > 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. > Ah, I see this now. Even within W-H-O, the same variable gets evaluated in some places: if I use a variable for an attribute value it gets evaluated, but but not when I use it as the tag body. This is clearly spelled out in the docs, I see now, but it took me a while to wrap my head around it. Thanks! Tyler