What you can do with macros in Lisp
Kenny Tilton
ktilton at nyc.rr.com
Sun Oct 12 10:46:32 EDT 2003
Tim Bradshaw wrote:
> Someone mentioned that there's been the usual futile argumentation
> between Lisp people and you-don't-need-macros-at-all and/or
> you-can-do-it-all-with-HOFs people.
The ancient context for this thread was a prior incarnation arising
amongst Pythonistas discussing on clp whether or not Python should have
macros in version 42, due out in fifteen years.
So I am adding clp in this otherwise unmodified version of your original.
Me, I finally realized two things: (a) Graham explains it better:
http://www.paulgraham.com/onlisp.html
..and two, hey, one of Python's most important design principle is
visually clean code. I think I use macros more for that than anything else.
kenny
>
> Here's something I'd like to see non-macro people do.
>
> Imagine you have a language with a CASE expression. You're writing
> (or generating: for instance in the output of some kind of FSM system)
> code that has a huge number of large, dense, integer CASE expressions,
> which can obviously be optimised into jump-tables. But your compiler
> won't do this, so your code is spending lots of time testing integers
> repeatedly.
>
> So: implement NCASE, which looks exactly like your language's CASE
> expression, but, if all the keys are numeric and if they pass some
> user-definable test - for instance that there are enough keys and they
> are dense enough in their range, will expand to a jump-table.
> Otherwise it should just expand to the ordinary CASE expression.
>
> Can you do this with macros in Lisp? Yes: in fact I did this ages
> ago, with results I've now put up at
> http://www.tfeb.org/lisp/toys.html#NCASE.
>
> Can you do it any other way (in partiucular: in any way which isn't
> equivalent to writing a macro system...)
>
> --tim
>
>
--
http://tilton-technology.com
What?! You are a newbie and you haven't answered my:
http://alu.cliki.net/The%20Road%20to%20Lisp%20Survey
More information about the Python-list
mailing list