Explanation of macros; Haskell macros

Peter Seibel peter at javamonkey.com
Thu Oct 30 18:29:00 EST 2003


"Anton van Straaten" <anton at appsolutions.com> writes:

> Peter Seibel wrote:
> > Joachim Durchholz <joachim.durchholz at web.de> writes:
> >
> > > Peter Seibel wrote:
> > > > Joachim Durchholz <joachim.durchholz at web.de> writes:
> > > >
> > > >>Efficiency issues aside: how are macros more intuitive than quoting?
> > > > Or you could do this:
> > > >   (when (> x y) #'(lambda () (print x)))
> > > > which could work but seems a bit convoluted (i.e. unintuitive)
> > > > compared to the macro version.
> > >
> > > Um, right, but that's just a question of having the right syntactic
> sugar.
> >
> > Uh right, that's what macros are for, providing the syntactic sugar.
> 
> Yes, but the point is that with a concise syntax for lambda, entire
> classes of macros can become unnecessary. That's how Smalltalk
> handles 'if', for example - no macros or special forms needed.

Okay, so I picked an unfortunate example in that it also falls in the
class of macros that become unecessary when other bits of syntactic
sugar are provided. How about this one.

Which is more intuitive?

This:

  (defun foo () (print "hello, world")))

Or this:

  (progn (eval-when (:compile-toplevel)
           (excl::check-lock-definitions-compile-time 'foo 'function
             'defun (fboundp 'foo))
           (push 'foo excl::.functions-defined.))
         (progn (eval-when (:compile-toplevel)
                  (excl::check-de-argdecl-change 'foo 'nil))
                (declaim (excl::dynamic-extent-arguments nil foo)))
         (setf (fdefinition 'foo)
               (let ((excl::f
                      (named-function foo
                        (lambda nil
                          (block foo (print "hello, world"))))))
                 (excl::set-func_name excl::f 'foo)
                 excl::f))
         (remprop 'foo 'excl::%fun-documentation)
         (record-source-file 'foo) 'foo)

-Peter

-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the Python-list mailing list