[erlang-questions] No Namespace for Macros

sapan shah sapan.gcet@REDACTED
Fri Oct 16 06:03:00 CEST 2009


On Fri, Oct 16, 2009 at 4:12 AM, Robert Virding <rvirding@REDACTED> wrote:

> Erlang macros are modeled directly on C macros, the version based on tokens
> and not on text. And as do C macros Erlang macros only exist within a
> preprocessor, they have no life of their own outside that. In this sense
> they are not like functions or variables from other languages.
>
> If we do the same thing in C, It surely gives 'redefining macro' as a
warning (not as an error).
& it considers the latest definition included in the file.


> It is important to realise that an include file does not have a life of its
> own, it only exists within the file which includes it. So anything defined
> in it becomes part of the including file and in this respect it is
> perfectly
> logical that there is only one namespace.
>
> Anyway that is the reasoning behind the way they are.
>
> Robert
>
> 2009/10/15 Attila Rajmund Nohl <attila.r.nohl@REDACTED>
>
> > Macros (and records) can be defined outside modules, unlike functions.
> > I think they are handled by a "preprocessor", not the compiler. Don't
> > forget that macros in C++ are also outside classes and namespaces -
> > the Erlang macro is modeled more like the C/C++ macros, not like Java
> > variables.
> >
> > 2009/10/15, sapan shah <sapan.gcet@REDACTED>:
> > > As Anupag said it rightly & Bengt showed... there is a way around..
> > > But my curiosity is,
> > > If it is for functions, why it is not for macros??? What would the
> > > developers of Erlang have thought & made it like that???
> > >
> > > On Thu, Oct 15, 2009 at 12:05 PM, Anupam Kapoor
> > > <anupam.kapoor@REDACTED>wrote:
> > >
> > >> ofcourse another way to skin the cat is to return constants from
> > >> functions in different modules...
> > >>
> > >>
> > >> On Thu, Oct 15, 2009 at 11:54 AM, Anupam Kapoor <
> > anupam.kapoor@REDACTED>
> > >> wrote:
> > >> >> For exapmle, Java supports this (public static final variables).
> > >> >>
> > >> >> Any Explanation?????
> > >> > erlang doesn't have any notion of objects. in java, each '.java'
> file
> > >> > contains a corresponding class-definition, and you can have multiple
> > >> > instances of those objects defined...
> > >> >
> > >> > kind regards
> > >> > anupam
> > >> >
> > >> > --
> > >> > In the beginning was the lambda, and the lambda was with Emacs, and
> > >> > Emacs was the lambda.
> > >> >
> > >>
> > >>
> > >>
> > >> --
> > >> In the beginning was the lambda, and the lambda was with Emacs, and
> > >> Emacs was the lambda.
> > >>
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Sapan Shah
> > >
> >
> > ________________________________________________________________
> > erlang-questions mailing list. See http://www.erlang.org/faq.html
> > erlang-questions (at) erlang.org
> >
> >
>



-- 
Regards,
Sapan Shah


More information about the erlang-questions mailing list