Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Lisp Macros in Mathematica (Re: If Scheme is so good why MIT

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102520] Re: Lisp Macros in Mathematica (Re: If Scheme is so good why MIT
  • From: Pillsy <pillsbury at gmail.com>
  • Date: Wed, 12 Aug 2009 04:34:23 -0400 (EDT)
  • References: <b0g665llur83sj9dnumktjvnipacj7bgrt@4ax.com> <17pco71asfk7d.1kd4oiidz6nqy.dlg@40tude.net>

On Aug 9, 6:17 pm, fft1976 <fft1... at gmail.com> wrote:

> On Jul 21, 5:31 am, Xah Lee <xah... at gmail.com> wrote:

> > Also, lisp's macros, a feature that gets lispers much ado about
> > nothing. In Mathematica (b ~1989), the whole language can be
> > considered as a extended lisp macros system. When i learned about
> > lisp's macros while practical coding elisp, i find lisp macros are
> > rather so trivial, painful to use, and laughable.

> Is this true?

Kinda sorta.

Mathematica evaluation is based on a rule-rewrite system, so
comparisons with more conventional languages like Lisp can be tricky,
but it provides the ability (through the Hold/HoldPattern/HoldComplete
facilities) to prevent code from being evaluated, and Mathematica code
is built out of data structures that you can easily manipulate from
within Mathematica.

You can also specify that functions Hold their arguments. Together,
that gives you something that approximates the Lisp macro system in
theory.

> How do you write some simple Lisp-like macros in
> Mathematica?

With difficulty. I find the absence of quasiquotation makes things
dramatically more difficult, and there's a mix of different functions
(the aforementioned Hold* functions and Unevaluated) that kind of act
like Lisp's QUOTE but not really, and unquoting is also a good deal
trickier. Mathematica's powerful pattern-matching and rule-rewriting
facilities don't close the gap IMO.

On top of that, the documentation that comes with Mathematica isn't
particularly helpful when it comes to doing macro-like things, and
there isn't anything like the reams of good tutorial material there is
on writing Lisp macros.

> Are Mathematica's macros like Scheme's hygienic macros or
> like Lisp's "low-level" macros?

More like Lisp's "low-level" macros, but you have to deal with a
number of Mathematica functions that try (with mixed results) to
prevent name clashes for you and, as often as not, defeat their
efforts. Also, in Mathematica, there apparently aren't any real
gensyms; the closest equivalent, Unique, actually interns the unique
symbols it creates.

Cheers,
Pillsy


  • Prev by Date: Re: video on Presentations by Williams and Park
  • Next by Date: Re: Sticky scaling? (for printing)
  • Previous by thread: Re: Lisp Macros in Mathematica (Re: If Scheme is so good
  • Next by thread: Formatting MatrixPower in TraditionalForm