Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interesting uses of Dylan macros

11 views
Skip to first unread message

dlwei...@gmail.com

unread,
Dec 17, 2008, 8:03:37 AM12/17/08
to
Hi. I am working on doing a presentation/paper about why Lisp
macros are valuable. I was wondering if you could tell me about
the experiences users have had with Dylan macros. Are there many
users? What are some of the more sophisticated/cool things
that have been done with Dylan macros?

The issue is: which of
the things Lisp macros do could have been done with
a conventional language that has some kind of macro-like
thing that's not just textual.

Thank you very much.

-- Dan Weinreb

P.S. Please consider attending the International Lisp
Conference 2009, at MIT (Cambridge, MA, USA)
March 22-25. See ilc09.org for details.

Dustin Voss

unread,
Dec 19, 2008, 1:27:26 AM12/19/08
to
In article
<097e0a8e-7d9a-4d78...@l39g2000yqn.googlegroups.com>,
dlwei...@gmail.com wrote:

Dylan macros aren't exactly like Lisp macros. Dylan macros are
token-based, but Lisp macros can be procedural.

Dylan's macros are kind of like textual macros, except that they
recognize and substitute tokens instead of strings. In practice, this
allows for more sophisticated recognition and substitution, but more
importantly, allows for hygienic variable references. A macro can create
its own variables, functions, classes, etc. without worrying about
namespace pollution.

Imagine a printout of source code. A Dylan macro is like two pieces of
cardboard. One piece of cardboard has holes cut into it and goes on top
of the printout. The holes recognize expressions, names, operators, etc.
The parts of the source code that show through the holes are altered
semantically (perhaps by adding commas between elements of a list or
appending to a name) and saved. The other piece of cardboard contains
new source code with gaps. The gaps are filled by the altered and saved
parts of the original source code, and then the completed new source
code replaces the original.

Token-based processing allows textual variable names to include extra
metadata that allows hygienic references. With hygienic references, you
can generate hidden boilerplate code.

Macros can make a dozen classes and related functions that implement an
entire subsystem based on a few options specified by the user, and then
only expose one part of that subsystem to the user, hiding the rest.

A good example of this is the C-FFI macros. They define Dylan classes
and accessors that create or interpret memory blocks compatible with C
structures and functions.

http://www.opendylan.org/documentation/opendylan/interop1/inter_82.htm

Another good example would be my parser, which uses macros to build a
number of parsing functions and infrastructure.

http://wiki.opendylan.org/wiki/view.dsp?title=PEG%20Parser%20Library

A third example would be Koala, which uses macros to build a web-server,
but I can't find documentation for it.

As a side effect of eliminating boilerplate code, Dylan macros can
extend the language. In fact, all of Dylan's statements are macros that
reduce to a primitive set of assignments, local methods, expressions,
and code blocks.

http://www.opendylan.org/books/drm/Rewrite_Rule_Examples

A smaller-scale example of a language extension is the table macro,
which simply creates a simple short-hand notation (similar to the
predefined list and vector constructors) for creating tables.

http://www.opendylan.org/gdref/gdcore/html/files/name-table-txt.html

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Hannes Mehnert

unread,
Dec 19, 2008, 9:36:10 AM12/19/08
to
Hi Dan,

On Dec 17, 8:03 am, dlweinr...@gmail.com wrote:
> Hi.  I am working on doing a presentation/paper about why Lisp
> macros are valuable.  I was wondering if you could tell me about
> the experiences users have had with Dylan macros.  Are there many
> users?  What are some of the more sophisticated/cool things
> that have been done with Dylan macros?

Take a look at "A Domain-Specific Language for manipulation of binary
data in Dylan" (ILC07), http://www.opendylan.org/~hannes/ilc07-final.pdf


> The issue is: which of
> the things Lisp macros do could have been done with
> a conventional language that has some kind of macro-like
> thing that's not just textual.
>
> Thank you very much.


But, also, non-standard Dylan macros used in Open Dylan (former
Harlequin)
Take a look at
http://www.opendylan.org/cgi-bin/viewvc.cgi/trunk/fundev/sources/dfmc/definitions/parse-signatures.dylan?revision=9780&view=markup

At the bottom you'll find "define method parse-signature-as" which
uses
macro-case(fragment), and then auxiliary macro rules on the left-hand
side,
and Dylan code on the right hand side, where each macro pattern
variable
(like ?args:*) is bound to a Dylan variable without '?' (args).

These procedural macros are described in
http://people.csail.mit.edu/jrb/Projects/dexprs.pdf


> P.S. Please consider attending the International Lisp
> Conference 2009, at MIT (Cambridge, MA, USA)
> March 22-25.  See ilc09.org for details.

I'll be there. :)


Regards,

Hannes Mehnert

0 new messages