[erlang-questions] Erlang programming question: "record abc already defined"

Anthony Kong anthony.hw.kong@REDACTED
Tue Jul 10 20:20:36 CEST 2007


Hi, all,

Thanks very much for your help. -ifndef is a very useful device.

I understand I did not give a lot of info in my first post, so I tried
to come up with a set of simpler scripts. In the process I realized
the mistake I made: In addition to the hrl, I have -include() other
erl files as well!

Now I understand why I were also getting "redefining module" error
message. Will do a better job in describing my problem next time.

Cheers, Anthony



On 7/9/07, Bengt Kleberg <bengt.kleberg@REDACTED> wrote:
> On 2007-07-08 23:56, Anthony Kong wrote:
> > Hi, all,
> >
> > It is a erlang question form a firsttime beginner. So, bear with me if
> > the source of problem is obvious.
>
> no problem, everybody was a beginner at some time.
>
>
> > I got a bunch of message like this when I run erlc against a number of
> > erl files. Here are some examples:
> >
> > ./reqmgt.hrl:14: record project already defined
> > ./reqmgt.hrl:14: record project already defined
> > ./reqmgt.hrl:14: record project already defined
> > ./reqmgt.hrl:14: record project already defined
> > ./reqmgt.hrl:14: record project already defined
> > ./reqmgt.hrl:14: record project already defined
>
> next time, could you give the whole command line?
> and perhaps just one example if they all look the same?
>
>
> > Let's say I have these files regmgt.erl, regmgt.hrl, project.erl,
> > abc.erl, def.erl.
> >
> > Except for the hrl files, they are all
>
> have you other hrl files, too?
> there is only one hrl file in you example, but you mention ''hrl files''.
>
>
> > 1) based on the gen_server_template.mini from Joe's book
> > 2) project, abc, def contains logic related to a particular record
> > class. So, project.erl knows how to handle -record(proect, {...})
> > 3) I am a java programmer, so the design of the project.erl, abc, def
> > are  basically to handle CRUD.
> > 4) reqmgt.erl is an implementation following a Facade pattern.
> > 5) each of these erl files has a line "-include (reqmgt.hrl)"
> >
> > in reqmgt.hrl I have define  "-record(project, {...})" and abc, def  etc.
> >
> > (Yes, I am using hrl as if it is a C include file but not knowing how
> > to do "#ifndef" :-) )
>
> in erlang you can do:
>
> -ifndef(MNESIA_TABLES_HRL).
> -define(MNESIA_TABLES_HRL, 1).
>
> %% lots of defines/records/etc
>
> -endif. % NIBS_MNESIA_TABLES_HRL defined
>
> > So, questions:
> >
> > 1) Is it wrong to use "-include" this way? If so, how to fix it?
>
> since you get a compile time error it sure is wrong :-)
> seriously, lots (a large majority, at a guess) of very good erlang
> programmers like to have records defined in common hrl files and shared
> in several erl files.
> i do not like the idea and try to avoid it if i can.
>
> > 2) Does this 'design' sound OK in erlang?
>
> one possibility is to hide your record in an erl file and have table
> create/access functions. that helps when loading new modules after
> upgrading records.
>
>
> bengt
> --
> Those were the days...
>     EPO guidelines 1978: "If the contribution to the known art resides
>     solely in a computer program then the subject matter is not
>     patentable in whatever manner it may be presented in the claims."
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>


-- 
/*--*/
Experience is simply the name we give our mistakes.
---- Oscar Wilde



More information about the erlang-questions mailing list