Luke Gorrie luke@REDACTED
Thu Sep 4 15:03:23 CEST 2003

Bengt Kleberg <Bengt.Kleberg@REDACTED> writes:

> greetings,
> 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

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.)

This is not "correct" in that it won't handle the case where real
macroexpansion would introduce more free variables, but anyone who
codes like that deserves that they get. (Hey, don't I sound like a
real software vendor? :-)

I can do a new Distel release if that would be helpful. I haven't
bothered yet because IIRC this is the only change since version
3.3. Or if you want to do a quick "hot fix", you can just replace your
erl-service.el with the one attached below.

(Thanks to Tobbe Törnkvist for using the refactoring feature enough to
motivate the fix :-)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: erl-service.el
Type: application/emacs-lisp
Size: 33544 bytes
Desc: erl-service.el with refactoring-with-macros fix
URL: <>

More information about the erlang-questions mailing list