Learning by reading code

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Learning by reading code

WILLIAMS Dominic
Hello,

I am trying to learn Erlang, and like to read code written by experienced Erlangers.
I came across the following things (in xmerl) for which I could find no explanation in the documentation:

-compile(export_all).

What does this mean? Does it automatically export all functions contained in the file?

'#text'(Text) ->
    export_text(Text).

There are lots of functions in xmerl with these funny names. Does this have any special significance?

Cheers,

Dominic.


Reply | Threaded
Open this post in threaded view
|

Learning by reading code

Ulf Wiger-4
On Tue, 27 May 2003, WILLIAMS Dominic wrote:

>Hello,
>
>I am trying to learn Erlang, and like to read code written
>by experienced Erlangers.

I think this is good, and I notice that you've been reading
my code. Hopefully, you will also keep in mind that
experienced programmers do not always set good examples. ;)


>I came across the following things (in xmerl) for which I
>could find no explanation in the documentation:

Apologies for the insufficient documentation.


>-compile(export_all).

>What does this mean? Does it automatically export all
>functions contained in the file?

Yes. It's a common way to start out when writing code. It
means that you can easily call all functions in a compiled
module from the shell. This makes it a lot easier to test
your code.

Normally, you're supposed to remove the -compile(export_all)
and specifically export only the functions that should be
exported. This is not always done. (:


>'#text'(Text) ->
>    export_text(Text).
>
>There are lots of functions in xmerl with these funny
>names. Does this have any special significance?

These appear in callback modules for exporting XML
structures (e.g. as HTML or XML text). The '#' is "namespace
management", identifying the functions as special control
functions. All other exported functions in such a module are
supposed to signify XML tags (i.e. the function name matches
the XML tag. Since '#text' is not a valid XML tag, there can
be no name clash.

/Uffe
--
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes



Reply | Threaded
Open this post in threaded view
|

Learning by reading code

Thomas Lindgren-5
In reply to this post by WILLIAMS Dominic

--- WILLIAMS Dominic <D.WILLIAMS>
wrote:

> Hello,
>
> I am trying to learn Erlang, and like to read code
> written by experienced Erlangers.
> I came across the following things (in xmerl) for
> which I could find no explanation in the
> documentation:
>
> -compile(export_all).
>
> What does this mean? Does it automatically export
> all functions contained in the file?

Yes. I think a more modern approach (at least when you
use makefiles) is to do

  erlc +export_all module.erl

and leave the -compile(...) attribute out. (Because
you can change the mass of options once in the
makefile instead of going through each module.)

(or in the top loop, use the clumsier
1> c(module, [export_all]).
)

Best,
Thomas


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


Reply | Threaded
Open this post in threaded view
|

Learning by reading code

Vance Shipley-2
In reply to this post by WILLIAMS Dominic
Dominic,

The directive is documented in the Erlang Specification:

        http://www.erlang.org/download/erl_spec47.ps.gz

While out of date this is the most definitive documentation
there exists on the core language.

   -Vance


On Tue, May 27, 2003 at 09:46:47AM +0200, WILLIAMS Dominic wrote:
}
}  I came across the following things (in xmerl) for which I could
}  find no explanation in the documentation:
}  
}  -compile(export_all).