From: Mike Cox
Subject: Trouble with Lisp Macros.
Date: 
Message-ID: <3d6111f1.0403161021.28b80797@posting.google.com>
I just got to the macros section of my lisp book, and I'm having
problems. How long does the average person take to get competent in
lisp macros?  I've learned a few frameworks, ATL, MFC, CORBA TAO, so I
know I'm capable of learning.  It's just that I just need to get
through this chapter, and then the next one about OOP programming and
then I'll know all there is to know about lisp.  My goal is to know a
bunch of languages well.  Here is a list that I know so far:
LANGUAGES:
C
C++
C#
Visual Basic
Visual Basic.NET
J# (Java)
pearl
assembly (x86)
lisp (75 percent learned)
SQL
HTML
Javascript

FRAMEWORKS / APIs:
MFC
ATL
Win32
SWING
WTL
CORBA TAO
ASP.NET

I know enough about lisp that I'm a master of emacs, it just that I
started reading about lisp macros last night.

From: Steven E. Harris
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <q67u10ocyw6.fsf@L75001820.us.ray.com>
············@yahoo.com (Mike Cox) writes:

> Here is a list that I know so far:

Hubris.

-- 
Steven E. Harris        :: ········@raytheon.com
Raytheon                :: http://www.raytheon.com
From: Gary Klimowicz
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <u4qsodt6q.fsf@C1799538-A.comcast.net>
"Steven E. Harris" <········@raytheon.com> writes:

> ············@yahoo.com (Mike Cox) writes:
>
>> Here is a list that I know so far:
>
> Hubris.

Hubris? Where do I learn how to write programs in Hubris?

;-)

-- 
gak
From: Peter Lewerin
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <dbc03c5a.0403170221.47e79a98@posting.google.com>
> Hubris? Where do I learn how to write programs in Hubris?
> 
> ;-)

You don't need anyone teaching you, you may assume that you have
mastered it already.

Mind you, it's not a language for the faint of heart.  All iteration
constructs loop forever but still stop at the appropriate moment;
selection structures handle branches not known at coding time.  It
uses not static, not dynamic, but fatalistic typing: however you
define your data and operations, it will all match up without
conflicts, somehow.  It supports full bidirectional compilation; you
can use a compiled program to recreate the source, the documentation,
and the complete platform it was originally compiled on.  Metamacros
allow you to not only rewrite the language, but to redefine the
specifications of the project, often useful for making implementation
easier!

See the homepage for code examples, including a oneliner that
determines if a given program hangs or completes.

Just Another Hubris Hacker
"Anything you can do, I can do better."
From: David Sletten
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <dLR5c.8287$Xd1.6717@twister.socal.rr.com>
Gary Klimowicz wrote:

> "Steven E. Harris" <········@raytheon.com> writes:
> 
> 
>>············@yahoo.com (Mike Cox) writes:
>>
>>
>>>Here is a list that I know so far:
>>
>>Hubris.
> 
> 
> Hubris? Where do I learn how to write programs in Hubris?
> 
> ;-)
> 
I think you need to be Greek and about 3000 years old.
From: Pascal Bourguignon
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <873c87ldcv.fsf@thalassa.informatimago.com>
David Sletten <·····@slytobias.com> writes:

> Gary Klimowicz wrote:
> 
> > "Steven E. Harris" <········@raytheon.com> writes:
> >
> >>············@yahoo.com (Mike Cox) writes:
> >>
> >>
> >>>Here is a list that I know so far:
> >>
> >>Hubris.
> > Hubris? Where do I learn how to write programs in Hubris?
> > ;-)
> >
> I think you need to be Greek and about 3000 years old.

That's funny: a google search on: Hubris programming language
gives a high number of Perl related pages in the first results...

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
From: Ray Dillinger
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <4058A660.58CD34B2@sonic.net>
Pascal Bourguignon wrote:
> 
> That's funny: a google search on: Hubris programming language
> gives a high number of Perl related pages in the first results...

This is because, according to Wall, two cardinal virtues of a good
programmer are Hubris and Laziness.  The quote is somewhat famous, 
and appears in the "Manifesto/philosophy" section of each version 
of the perl manual.

				Bear
From: Kenny Tilton
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <sqJ5c.52228$Wo2.2969@twister.nyc.rr.com>
Mike Cox wrote:
> I just got to the macros section of my lisp book, and I'm having
> problems. How long does the average person take to get competent in
> lisp macros?

How will you scale the answer for an average person to a master such as 
yourself? I used to like 5 for things like that, but someone here said 
that could trigger an IRS audit. I would use 6, but then the Gibsonites 
would boycott Cello. (Cello, Hello, Hell...right?)

   I've learned a few frameworks, ATL, MFC, CORBA TAO, so I
> know I'm capable of learning.  It's just that I just need to get
> through this chapter, and then the next one about OOP programming and
> then I'll know all there is to know about lisp.

Are you still reading? I had written a WYSIWYG math editor after a week.

   My goal is to know a
> bunch of languages well.  Here is a list that I know so far:
> LANGUAGES:
> C
> C++
> C#
> Visual Basic
> Visual Basic.NET
> J# (Java)
> pearl
> assembly (x86)
> lisp (75 percent learned)

The bad news is that that last 25% is accomplished asymtotically, so you 
are going to blow past that Lisp-in-24-Days pretty badly.

> SQL
> HTML
> Javascript
> 
> FRAMEWORKS / APIs:
> MFC
> ATL
> Win32
> SWING
> WTL
> CORBA TAO
> ASP.NET
> 
> I know enough about lisp that I'm a master of emacs, it just that I
> started reading about lisp macros last night.

I'd give it another ten minutes, then get back to us if you are still 
having trouble. Hint: stop reading, these you have to write. Remember to 
think fluently about the different times: read, compile, and run. 
Someone will remind me of the fourth, but I keep forgetting that one.

Put print statements in and around the expansion you are trying to 
generate to get a feel for read-time vs run-time.

kt

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: szymon
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <c37lqt$eii$1@korweta.task.gda.pl>
Mike Cox, 3lite Troll wrote:

> I just got to the macros section of my lisp book, and I'm having
> problems. How long does the average person take to get competent in
> lisp macros?

imho, more than 10 days[*] (av. idiot (me) I'm not programmer).

* "on lisp" book by Paul Graham.

>  I've learned a few frameworks, ATL, MFC, CORBA TAO, so I
> know I'm capable of learning.  It's just that I just need to get
> through this chapter, and then the next one about OOP programming and
> then I'll know all there is to know about lisp.  My goal is to know a
> bunch of languages well.  Here is a list that I know so far:
> LANGUAGES:
> C
[.....]
> J# (Java)
> pearl

perl?

> assembly (x86)
-----
> lisp (75 percent learned)

I think you eat dot.
-----
> SQL
> HTML
> Javascript
> 
> FRAMEWORKS / APIs:
[.....]
> I know enough about lisp that I'm a master of emacs, it just that I

You are master of emacs and you "have problems" with macros, ROTFL.

> started reading about lisp macros last night.

regards, szymon.
From: Joe Marshall
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <oeqwwbjp.fsf@comcast.net>
············@yahoo.com (Mike Cox) writes:

> I just got to the macros section of my lisp book, and I'm having
> problems. How long does the average person take to get competent in
> lisp macros?  

Don't let those naysayers get you down.  You should be able to learn
lisp macros in a few minutes.  The key is quasiquote.  This allows you
to make code templates that the macro can then fill in.  A simplified
version of the algorithm (due to Alan Bawden) is fairly obvious:

(defun quasiquote-expand (x) 
  (cond ((tag-comma-p x) (tag-data x))
        ((tag-comma-atsign-p x) (error "Illegal"))
        ((tag-backquote-p x) 
         (quasiquote-expand
          (quasiquote-expand (tag-data x))))
        ((consp x) `(append ,(quasiquote-expand-list (car x))
                            ,(quasiquote-expand (cdr x))))
        (t `',x)))

(defun quasiquote-expand-list (x) 
  (cond ((tag-comma-p x) `(list ,(tag-data x)))
        ((tag-comma-atsign-p x) (tag-data x))
        ((tag-backquote-p x) 
         (quasiquote-expand-list 
           (quasiquote-expand (tag-data x))))
        ((consp x) `(list 
                     (append ,(quasiquote-expand-list (car x))
                             ,(quasiquote-expand-list (cdr x)))))
        (t `'(,x))))

This should illustrate:

(defmacro defsubst (name lambda-list &body body)
  "Identical to DEFUN except that it arranges for the body to be INLINED
   in the places it is called."
  (let ((form-var (gensym "FORM-")))
    `(progn (defun ,name ,lambda-list ,@body)
	    (eval-when (:compile-toplevel :load-toplevel :execute)
	      (define-compiler-macro ,name (&whole ,form-var ,@lambda-list)
		(declare (ignore ,@lambda-list))
		(if *enable-inlinep*
		      `(,',`(lambda ,lambda-list
			      (block ,name (locally ,@(if (stringp (car body))
							      (cdr body)
							    body))))
			   ,@(cdr ,form-var))
		    ,form-var))))))

This can be used to good effect in a macrolet:

    (macrolet ((trinary-query (query-arg? query-arg query-result-var)
		 (let ((not-result-var '#:not-result))
		   `(when ,query-arg?
		      `((let ((,',query-arg ,,query-arg)
			      (,',not-result-var (not ,',query-result-var)))
			  (ecase ,',query-arg
			    ((nil) t)		; don't care
			    (:yes (not ,',not-result-var))
			    (:no ,',not-result-var))))))))

And of course, combining the two:

(defmacro xhtml (req &body body)
  (with-unique-names (command ticket comment success-page fail-page)
   `(progn
      (emit-xhtml-header (request-reply-stream ,req))
      (macrolet ((applet (,command ,ticket ,comment ,success-page ,fail-page)
       `(html
         ((:P ,,comment)
          ((:object 
            :code "applet.class"
            :id "applet"
            :width  "100%"
            :height "300"
            :standby "Loading applet...")
           ((:param :name "URL"
                    :value (render-uri (extend-uri-query
                                        (request-uri req)
                                        '(:absolute "applet-page.htm")
                                        `((:command . ,',,command)
                                          (:ticket . ,,,ticket)))
                                       nil))))))))
        (html ,@body))
      (emit-xhtml-trailer (request-reply-stream ,req)))))

If you want to experiment with macros, the following may be helpful:

(defmacro call-with-macroenvironment (receiver &environment env)
  `',(funcall receiver env))

Lisp macros really aren't all that mysterious.

-- 
~jrm
From: David Fisher
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <14030ca9.0403171158.69dad063@posting.google.com>
············@yahoo.com (Mike Cox) wrote in message news:<····························@posting.google.com>...
> I just got to the macros section of my lisp book, and I'm having
> problems. How long does the average person take to get competent in
> lisp macros?  I've learned a few frameworks, ATL, MFC, CORBA TAO, so I
> know I'm capable of learning.  It's just that I just need to get
> through this chapter, and then the next one about OOP programming and
> then I'll know all there is to know about lisp.  My goal is to know a
> bunch of languages well.  Here is a list that I know so far:
> LANGUAGES:
> C
> C++
> C#
> Visual Basic
> Visual Basic.NET
> J# (Java)
> pearl
> assembly (x86)
> lisp (75 percent learned)
> SQL
> HTML
> Javascript
> 
> FRAMEWORKS / APIs:
> MFC
> ATL
> Win32
> SWING
> WTL
> CORBA TAO
> ASP.NET
> 
> I know enough about lisp that I'm a master of emacs, it just that I
> started reading about lisp macros last night.

To someone who knows Lisp, but not macros, I could explain macros in 5
minutes, but a guru like you should grasp them in seconds ;-)

A macro is an operator that takes code (which is a list), transforms
it into another code (also a list), and puts the result into the
program instead of the original and itself. The End.
From: Ray Dillinger
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <4058A5D8.15A39184@sonic.net>
Mike Cox wrote:
> 
> I just got to the macros section of my lisp book, and I'm having
> problems. How long does the average person take to get competent in
> lisp macros?  

Short answer:  Average people do not become competent with lisp macros.

				Bear
From: James P. Massar
Subject: Re: Trouble with Lisp Macros.
Date: 
Message-ID: <92lh50p8lderimrrfo85j7o91fvd9b5kdh@4ax.com>
On 16 Mar 2004 10:21:40 -0800, ············@yahoo.com (Mike Cox)
wrote:

>I just got to the macros section of my lisp book, and I'm having
>problems. How long does the average person take to get competent in
>lisp macros? 

Try chapters 7, 8 and 9:

http://www.gigamonkeys.com/book/