free_vars/1

Richard Carlsson <>
Thu Sep 4 15:21:41 CEST 2003


On Thu, 4 Sep 2003, Luke Gorrie wrote:

> Bengt Kleberg <> writes:
>
> > i have been using the function free_vars/1 (see end of email) by
> > Richard Carlsson(?). it is very helpful when refactoring
> > code. unfortunatly it throws an error when given a
> > macro. erl_parse:parse_exprs/1 returns {error, {Line, erl_parse,
> > Reason}} when fed a macro.
> >
> > my solution has been to change macros to atoms, like this:
> >
> > macros_to_atoms( [] ) ->
> > 	[];
> > macros_to_atoms( [{'?',_Nr}, {_Type, Nr, Macro}|T] ) ->
> > 	[{atom, Nr, Macro} | macros_to_atoms( T )];
> > macros_to_atoms( [H|T] ) ->
> > 	[H | macros_to_atoms( T )].
> >
> > before calling erl_parse:parse_exprs/1.
> >
> > is there a better way?
>
> Are you doing this via Distel? (Distel has a command to automate this
> refactoring.)
>
> This is taken care of in the CVS version of Distel. My solution was to
> remove all the macros with some Elisp code before sending it to Erlang
> and Richard's analysis program. Specifically, "?ANYTHING" becomes
> "deadmacro". (It's okay to mutilate the code arbitrarily so long as
> the set of free variables is preserved.)

If you take a look at the module 'epp_dodger.erl' in the syntax_tools
contribution, it does a similar trick to get code containing macros past
the parser. (It handles most "sane" uses of macros.) You might be able
to use it directly, or just steal some parts of the code.

	/Richard


Richard Carlsson ()   (This space intentionally left blank.)
E-mail: 	WWW: http://user.it.uu.se/~richardc/
 "Having users is like optimization: the wise course is to delay it."
   -- Paul Graham



More information about the erlang-questions mailing list