Subject: Re: What is the main advantage of macros over functions?
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 05 Jan 2006 05:28:17 -0600
Newsgroups: comp.lang.lisp
Message-ID: <W_adnSqHxPtMnyDeRVn-uQ@speakeasy.net>
Majorinc, Kazimir  <false@email.address> wrote:
+---------------
| I've frequently read that macros are one of the most important 
| strengths of Lisp, however, I do not understand why. 
...
| Am I missing something here? 
+---------------

Yes. Take a look at, say, HTOUT <http://www.cliki.net/htout> or
CL-WHO <http://www.cliki.net/CL-WHO>, both of which let you write
things like this:

    (let ((title "Simple Test Page"))
      (with-html-output (s *standard-output*)
	(:html
	  (:head (:title title)) (lfd)
	  ((:body :bgcolor "#d0d0ff")
	   (:h1 title) (lfd)
	   "This is a small demo table:" (lfd)
	   (:table (lfd)
	     (:tr (:th "i") (:th "2^i") (:th "10^i")) (lfd)
	     (loop for i below 5
		   for 2^i = (expt 2 i)
		   and 10^i = (expt 10 i) do
	       (htm (:tr (:td i) (:tr 2^i) (:tr 10^i))
		    (lfd))))))))

and get this output:

    <HTML><HEAD><TITLE>Simple Test Page</TITLE></HEAD>
    <BODY BGCOLOR='#d0d0ff'><H1>Simple Test Page</H1>
    This is a small demo table:
    <TABLE>
    <TR><TH>i</TH><TH>2^i</TH><TH>10^i</TH></TR>
    <TR><TD>0</TD><TR>1</TR><TR>1</TR></TR>
    <TR><TD>1</TD><TR>2</TR><TR>10</TR></TR>
    <TR><TD>2</TD><TR>4</TR><TR>100</TR></TR>
    <TR><TD>3</TD><TR>8</TR><TR>1000</TR></TR>
    <TR><TD>4</TD><TR>16</TR><TR>10000</TR></TR>
    </TABLE></BODY></HTML>

Yes, you can do HTML generation without macros, but it
tends to be ugly and full of deeply-nested LAMBDAs...


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607