[erlang-questions] How to avoid copying code?

attila.rajmund.nohl <>
Mon Nov 27 13:43:16 CET 2006

On Mon, 27 Nov 2006, Bengt Kleberg wrote:

> On 2006-11-25 11:53, Mazen wrote:
> ...deleted
>> Obviously this function definition is exactly the same in all 20-30
>> modules, which I don't really like. Is there a way to define this
>> function only once? In Java I'd create an abstract ancestor class for
> how about having one module with the common code for this function, and
> then let all 20-30 other modules call this module for the common parts
> and only supply the module specific things (like values) on the 20-30
> modules?

Actually this is what I'm trying to achieve. My problem was that how
should I pass the module-specific values (in macros) to the common
code. However, If I not call the common parts, but include them
directly, I won't need to pass these data. For example, instead of:

f(SomeData, ModuleSpecifiData) ->

lib:f(something, ?moduleData).

I'd try this:
f(SomeData) ->
  ... use ?moduleData here



"Beware of bugs in the above code; I have only proved it correct, not
  tried it."

More information about the erlang-questions mailing list