l-lang-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[L-lang-devel] Expanders with lexical scope and side effects


From: Matthieu Lemerre
Subject: [L-lang-devel] Expanders with lexical scope and side effects
Date: Sat, 05 May 2007 19:25:29 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux)

Some expanders create a lexical scope in which expansion is done
differently ; examples are @block ({}, which controls expansion of
lets) or make_list (which controls expansion of make).

An important problem arises when another expander needs to expand some
code which depends on other features. For instance, an expander might
expand into some code that uses a variable before it is declared with
let, i.e. code like

(d = 3)
(let d:Int)

It might also want to expand some code that uses d to known its type;
but d isn't yet declared.

These kind of problems don't appear in Lisp because of the dynamic
typing system, and because expansion is always done "top to bottom";
whereas L's macro expansion system is more complicated.

To cope with this problem, a functional interface to these expanders
is needed: these are the declare_* (begin|end)? functions. Ex:

  declare_block_begin();
  declare_let('id',Int); //or expand(Form(let id:Int));
  subform_list = expand(Form(id + id));
  form = declare_block_end(subform_list);

Is equivalent to expand({ let id:Int; id+id });

except that expansion is done in a more convenient order.

Similarly:

  declare_make_list_begin();
  form = expand(Form(make('toto')));
  fin_form = declare_make_list_end(form);

Will perfectly work, and fin_form is equivalent to

  fin_form = expand(make_list(make('toto')));


The expander functions of such lexical-scope expanders are reduced to:

expander make_list(form) = { declare_make_list_begin(); return
declare_make_list_end(form.form_list.head)};




reply via email to

[Prev in Thread] Current Thread [Next in Thread]