[erlang-questions] implementing annotation in erlang

paweł kamiński kamiseq@REDACTED
Thu Sep 3 00:12:02 CEST 2009


yes sure, but you need to somehow insert the association into the
dict/list/ets whatever, I dont want to do it manually, I would like to mark
my function (like in java, yes Im aware that erlang is not java:) with some
metadata that is far simpler to maintain in development cycle. so the
problem is how to put name->fun mapping into some structure rather than what
type of the structure to use.

the simplest solution would be to have a fun in the module like

*commandMap()->
    NewMap = dict:new(),
    Map1 = dict:store("**getDevTimeCmd", **getTime, NewMap),
    Map2 = dict:store("**getDevTimeCmd", **getTime, Map1),
    ..
    MapN
    .*

but then every time I change my function name or command name or add or
delete something I need to update commandMap as well in every command
module, I would rather write one general function that gets info about
function and generates insert to the structure so I can focus on more
interesting things.

pozdrawiam
Paweł Kamiński

kamiseq@REDACTED
pkaminski.prv@REDACTED
______________________


2009/9/2 Igor Ribeiro Sucupira <igorrs@REDACTED>

> From what I understand, you want to associate names with functions, so
> that you can decide which function to run just by "calling its name".
>
> If I am right, one way to implement what you want is to have a dict
> holding those associations (Name -> Function). That dict could be the
> responsibility of a named process, that would provide a wrapper (a
> message-passing "API") for the dict operations.
>
> Or you could use ets.
>
> Igor.
>
> 2009/9/2 paweł kamiński <kamiseq@REDACTED>:
> > hi,
> > I need to implement simple command dispatcher like this
> >
> > *[{cmdA, module_name, funA},{cmdB, module_name, funB}, ...] *
> >
> > and then use it with each call to my process with specific command name.
> But
> > then every time I change or add function I need to remember to manually
> > change cmd-fun list.
> > normally I would annotate a function with command name (ie
> > @command(name="getDevTimeCmd")) and then use the information to build
> > dispatcher map while initializing object.
> >
> > I know I can use *module_info()*  to get list of all exported function in
> > the module, but then I can't decide which function is command's callback
> nor
> > define a name of the command(and use only function name instead).
> >
> > The promising solution I'm thinking about is to use macro
> > *-define(command(Name, Fun), assignCommandCallback(Name, Fun)).*
> > and
> > *?command("getDevTimeCmd", getTime).
> > getTime(Args)->... .*
> >
> > but I'm not really sure how to use the information provided that way,
> when
> > the assignCommandFun/2 will be executed???
> >
> > tanks for any suggestions
> >
> > pozdrawiam
> > Paweł Kamiński
> >
> > kamiseq@REDACTED
> > pkaminski.prv@REDACTED
> > ______________________
> >
>


More information about the erlang-questions mailing list