[erlang-questions] No Namespace for Macros

Bengt Kleberg bengt.kleberg@REDACTED
Thu Oct 15 08:30:07 CEST 2009


Greetings,

You might want to look into using the following for your example:


house.erl:
-module(house).
-export([value/0]).
value() -> 10.


car.erl:
-module(car).
-export([value/0]).
value() -> 2.



bengt

On Thu, 2009-10-15 at 11:24 +0530, sapan shah wrote:
> Hi,
> 
> Erlang does have the concept of namespace for the functions( we do
> lists:map(...))
> Why does it not have this concept for macros?
> 
> Consider this scenario: I have an application which deals with the value of
> some things. (lets say a house & a car)
> So, I define macros in two different files for the things.
> %%%%valueHouse.hrl
> -define(Value, 10).
> %%%%valueCar.hrl
> -define(Value, 2).
> 
> Now, My application file could be something like this
> %%%application.erl
> -module(application).
> -include("valueHouse.hrl").
> -include("valueCar.hrl").  %% This will not compile... ll give 'redefining
> macro error'... assume it is allowed in erlang
> 
> star(X) ->
>        case X of house -> ?valueHouse:Value;
>                        car -> ?valueCar:Value
>         end.
> %%%%%%%%%%%%%%%%%%
> 
> This is just a cooked up example. One may have this kind of need in a big
> application.
> For exapmle, Java supports this (public static final variables).
> 
> Any Explanation?????
> 
> Regards,
> Sapan Shah



More information about the erlang-questions mailing list