[erlang-questions] implementing annotation in erlang

Igor Ribeiro Sucupira igorrs@REDACTED
Wed Sep 2 21:47:22 CEST 2009

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


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