[erlang-questions] Function Dependency

Justin Calleja calleja.justin@REDACTED
Mon Aug 20 23:48:01 CEST 2012


Hi Tyron,

I have never used xref myself but if it doesn't fit your needs you could
roll up your own custom transformation on the parsed version of the code
you're trying to compile. Of course, I am assuming you have access to the
source code here. Not sure what you meant by "extract a function clause by
knowing its signature only" but it seems to suggest that you're looking for
something along these lines.

Basically, when compiling your source code you can pass in an option to the
compiler, {parse_transform, ModuleName} where ModuleName is expected to
contain parse_transform/2 which will be passed an encoding of the source
code you're compiling before it is actually compiled (i.e. an abstract
syntax tree encoded in Erlang terms).

You can then do your analyzing (checking what functions are depended on)
and extracting inside ModuleName:parse_transform/2, making sure to return
something to compile.

Hi Richard,

Here's one instance that comes to mind with regards to wanting part of a
function definition (i.e. just some of it's clauses):
When implementing a gen_server you handle synchronous requests using
handle_call/3. You might just want the implementation of handle_call/3
which deals with certain messages.

That is just something off the top of my head. There could be other reasons.

cheers,
Justin

On 19 August 2012 17:49, Richard O'Keefe <ok@REDACTED> wrote:

>
> On 19/08/2012, at 11:52 AM, Tyron Zerafa wrote:
> >     Is there a way in Erlang which can give me a function's dependencies?
>
> It's an open source system.
> You have full source code for the compiler and everything.
> You can readily get the parsed form of any source file.
>
> You can even (gasp, the technology!) do a web search for
> "Erlang cross reference" and discover
> http://www.erlang.org/doc/apps/tools/xref_chapter.html
> which says
> "Xref is a cross reference tool that can be used for
>  finding dependencies between functions, modules, applications
>  and releases.  It does so by analyzing the defined
>  functions and the function calls."
>
> >  Such as dependency_of_fun(A) will result in all functions' names
> (including modules)
> >  being used in A?
>
> See the Xref documentation.
>
> > Also, apart from this, can I somehow extract a function clause by
> knowing its signature only?
>
> Signature?  The Erlang equivalent of a signature is a -spec.
> Function clauses don't have names, signatures, specifications, or anything
> else.
> It really makes no sense to extract just one clause from a function.
> I mean, here is a two-clause function:
>
>         app([], L) -> L;
>         app([H|T], L) -> [H|app(T, L)].
>
> What good does it do you just to have ``app([], L) -> L''?
> What are you going to do with half of a function (or less)?
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120820/66bcc113/attachment.htm>


More information about the erlang-questions mailing list