[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extensible syntax
On Dec 10, 2003, at 23:42, Tom Locke wrote:
> There's Dylan, with its template based macro system, but Dylan syntax
> is only extensible within a fairly strict framework. It always looks
> like Dylan. Agree?
Somewhat. You can’t change the lexical grammar, and pairs like () {} []
must all be balanced. However, you can certainly define DSLs that look
quite different from the standard Dylan statement macros.
As an example of how far away from Dylan you can get with Dylan macros,
take a look at the dom-builder library. The source, which contains
usage examples, is available here:
<http://www.gwydiondylan.org/cgi-bin/viewcvs.cgi/examples/dylanlibs/
dylanlibs/utilities/dom-builder/dom-builder.dylan?rev=1.1&content-
type=text/vnd.viewcvs-markup>
This library contains a macro for building Document Object Model
objects for output to HTML and XML, and defines a syntax that looks
much less like Dylan and more like Lisp:
with-dom-builder () // introduces the start of the DSL
(html
(head (title ["Test Page"])),
(body
(p ["The sum of 1 and 2 is "], [1 + 2]))) end;
which can be used to generate the following HTML:
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p>The sum of 1 and 2 is 3</p>
</body>
</html>
The tags “html”, “head”, “body”, and “p” are converted to symbols by
the macro. The macro knows nothing about the set of possible tags.
Anything inside square brackets [] is evaluated as a Dylan expression
and then converted to a string.
Notably, this DSL is not just an alternative syntax for Dylan function
calls, despite the parenthesis.
--
Chris Page - Software Wrangler - palmOne, Inc.
Dylan + You = Code
<http://www.gwydiondylan.org/>
<http://www.cafepress.com/chrispage>