implementing annotation in erlang

paweł kamiński kamiseq@REDACTED
Wed Sep 2 21:15:12 CEST 2009

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

Paweł Kamiński


More information about the erlang-questions mailing list