[erlang-questions] Re: implementing annotation in erlang

Steve Vinoski vinoski@REDACTED
Thu Sep 3 09:48:00 CEST 2009


2009/9/3 paweł kamiński <kamiseq@REDACTED>

> 2009/9/3 Igor Ribeiro Sucupira <igorrs@REDACTED>
>
> > Hi, Steve.
> >
> > I believe Pawel is not worried about having to recompile.
> >
> > The key (most difficult) functionality he needs is to be able to
> > change the name of a function without having to change *anything*
> > more.
> >
>
> hurray, finally somebody got it :). I will look closely at Fred's solution.
> anyway in arlang web 1.3 there are annotation, but I dont understand them
> at
> the moment how they are created and mapped to some fun invocation.
>
> is there a reason that erlang dont have more advanced (over module_info())
> reflection api??
>

I believe you could easily take Fred's custom attribute solution but write a
parse transform to replace the attribute with a generated exported function
in the module that would return the necessary mapping information. If you
gave that function the same name in every module, perhaps giving it an
uppercase name like 'COMMAND_MAP' so it would be unlikely to clash with
normal function names, you could use Fred's technique of walking the modules
at runtime but either use beam_lib:chunks(module, [exports]) to see if a
given module has such a function, or just try to invoke it under a catch and
ignore the ones that result in errors.

--steve


More information about the erlang-questions mailing list