[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[L-lang-devel] New Form library added
From: |
Matthieu Lemerre |
Subject: |
[L-lang-devel] New Form library added |
Date: |
Thu, 01 Feb 2007 23:39:11 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
I just added support for Forms from L into CVS. Forms are L's
representation of abstract syntax trees; and are used to manipulate L
code by itself. This is the way expanders, macros ... work.
Forms are manipulated through a templating mechanism, like in the XML
library, and a bit like the Lisp `/,/,@ operators.
Here are some exerpts of the test file:
let Form f3 = Form (3 + 4);
The most basic way to create a new form is to use Form(<L code>),
where <L code> can be either a L statement or a L expression.
let Form f2 = Form (let Int i = $f3;);
To create non-constant Forms, you can inserts $<expression> in your
code, where expression must return a Form. In this exemple, we insert
f3 in the code; so this has the same effect than of typing
let Form f2 = Form (let Int i = 3 + 4;);
For instance, a while macro transformer function could be written as
follow:
Form test_while (Form condition, Form body)
{
let Form while_form = Form (
loop {
if(!($condition))
break;
$body;
}
);
while_form
}
test_while (Form (i >= 0),
Form (i = i - 1;));
The second other operator is $@<expression>, that inserts a list of
Forms (instead of a single form, like $ does).
let List (Form) fl = list (f2, f3);
let Form test_form_list = Form ({let Int i = 3;
{$f; address@hidden;
i = 4;
address@hidden (f3, f2); });
So to compare with Common Lisp same facilities, Form is like `, $ like
, and $@ like ,@.
Have fun,
Matthieu
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [L-lang-devel] New Form library added,
Matthieu Lemerre <=