aboutsummaryrefslogtreecommitdiffstats
path: root/system/doc/getting_started/records_macros.xml
diff options
context:
space:
mode:
Diffstat (limited to 'system/doc/getting_started/records_macros.xml')
-rw-r--r--system/doc/getting_started/records_macros.xml109
1 files changed, 57 insertions, 52 deletions
diff --git a/system/doc/getting_started/records_macros.xml b/system/doc/getting_started/records_macros.xml
index 73c8ce5c8d..dd2441b64e 100644
--- a/system/doc/getting_started/records_macros.xml
+++ b/system/doc/getting_started/records_macros.xml
@@ -8,16 +8,17 @@
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
- The contents of this file are subject to the Erlang Public License,
- Version 1.1, (the "License"); you may not use this file except in
- compliance with the License. You should have received a copy of the
- Erlang Public License along with this software. If not, it can be
- retrieved online at http://www.erlang.org/.
-
- Software distributed under the License is distributed on an "AS IS"
- basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- the License for the specific language governing rights and limitations
- under the License.
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
</legalnotice>
@@ -29,27 +30,32 @@
<file>record_macros.xml</file>
</header>
<p>Larger programs are usually written as a collection of files with
- a well defined interface between the various parts.</p>
+ a well-defined interface between the various parts.</p>
<section>
<title>The Larger Example Divided into Several Files</title>
- <p>To illustrate this, we will divide the messenger example from
- the previous chapter into five files.</p>
- <taglist>
- <tag><c>mess_config.hrl</c></tag>
- <item>header file for configuration data</item>
- <tag><c>mess_interface.hrl</c></tag>
- <item>interface definitions between the client and the messenger</item>
- <tag><c>user_interface.erl</c></tag>
- <item>functions for the user interface</item>
- <tag><c>mess_client.erl</c></tag>
- <item>functions for the client side of the messenger</item>
- <tag><c>mess_server.erl</c></tag>
- <item>functions for the server side of the messenger</item>
- </taglist>
- <p>While doing this we will also clean up the message passing
- interface between the shell, the client and the server and define
- it using <em>records</em>, we will also introduce <em>macros</em>.</p>
+ <p>To illustrate this, the messenger example from
+ the previous section is divided into the following five files:</p>
+ <list type="bulleted">
+ <item>
+ <p><c>mess_config.hrl</c></p>
+ <p>Header file for configuration data</p></item>
+ <item>
+ <p><c>mess_interface.hrl</c></p>
+ <p>Interface definitions between the client and the messenger</p></item>
+ <item>
+ <p><c>user_interface.erl</c></p>
+ <p>Functions for the user interface</p></item>
+ <item>
+ <p><c>mess_client.erl</c></p>
+ <p>Functions for the client side of the messenger</p></item>
+ <item>
+ <p><c>mess_server.erl</c></p>
+ <p>Functions for the server side of the messenger</p></item>
+ </list>
+ <p>While doing this, the message passing interface between the shell,
+ the client, and the server is cleaned up and is defined
+ using <em>records</em>. Also, <em>macros</em> are introduced:</p>
<code type="none">
%%%----FILE mess_config.hrl----
@@ -244,14 +250,14 @@ server_transfer(From, Name, To, Message, User_List) ->
<section>
<title>Header Files</title>
- <p>You will see some files above with extension <c>.hrl</c>. These
- are header files which are included in the <c>.erl</c> files by:</p>
+ <p>As shown above, some files have extension <c>.hrl</c>. These
+ are header files that are included in the <c>.erl</c> files by:</p>
<code type="none">
-include("File_Name").</code>
<p>for example:</p>
<code type="none">
-include("mess_interface.hrl").</code>
- <p>In our case above the file is fetched from the same directory as
+ <p>In the case above the file is fetched from the same directory as
all the other files in the messenger example. (*manual*).</p>
<p>.hrl files can contain any valid Erlang code but are most often
used for record and macro definitions.</p>
@@ -265,64 +271,63 @@ server_transfer(From, Name, To, Message, User_List) ->
<p>For example:</p>
<code type="none">
-record(message_to,{to_name, message}).</code>
- <p>This is exactly equivalent to:</p>
+ <p>This is equivalent to:</p>
<code type="none">
{message_to, To_Name, Message}</code>
- <p>Creating record, is best illustrated by an example:</p>
+ <p>Creating a record is best illustrated by an example:</p>
<code type="none">
#message_to{message="hello", to_name=fred)</code>
- <p>This will create:</p>
+ <p>This creates:</p>
<code type="none">
{message_to, fred, "hello"}</code>
- <p>Note that you don't have to worry about the order you assign
+ <p>Notice that you do not have to worry about the order you assign
values to the various parts of the records when you create it.
The advantage of using records is that by placing their
definitions in header files you can conveniently define
- interfaces which are easy to change. For example, if you want to
- add a new field to the record, you will only have to change
+ interfaces that are easy to change. For example, if you want to
+ add a new field to the record, you only have to change
the code where the new field is used and not at every place
the record is referred to. If you leave out a field when creating
- a record, it will get the value of the atom undefined. (*manual*)</p>
+ a record, it gets the value of the atom <c>undefined</c>. (*manual*)</p>
<p>Pattern matching with records is very similar to creating
records. For example, inside a <c>case</c> or <c>receive</c>:</p>
<code type="none">
#message_to{to_name=ToName, message=Message} -></code>
- <p>is the same as:</p>
+ <p>This is the same as:</p>
<code type="none">
{message_to, ToName, Message}</code>
</section>
<section>
<title>Macros</title>
- <p>The other thing we have added to the messenger is a macro.
+ <p>Another thing that has been added to the messenger is a macro.
The file <c>mess_config.hrl</c> contains the definition:</p>
<code type="none">
%%% Configure the location of the server node,
-define(server_node, messenger@super).</code>
- <p>We include this file in mess_server.erl:</p>
+ <p>This file is included in <c>mess_server.erl</c>:</p>
<code type="none">
-include("mess_config.hrl").</code>
<p>Every occurrence of <c>?server_node</c> in <c>mess_server.erl</c>
- will now be replaced by <c>messenger@super</c>.</p>
- <p>The other place a macro is used is when we spawn the server
- process:</p>
+ is now replaced by <c>messenger@super</c>.</p>
+ <p>A macro is also used when spawning the server process:</p>
<code type="none">
spawn(?MODULE, server, [])</code>
- <p>This is a standard macro (i.e. defined by the system, not
- the user). <c>?MODULE</c> is always replaced by the name of
- current module (i.e. the <c>-module</c> definition near the start
+ <p>This is a standard macro (that is, defined by the system, not by
+ the user). <c>?MODULE</c> is always replaced by the name of the
+ current module (that is, the <c>-module</c> definition near the start
of the file). There are more advanced ways of using macros with,
- for example parameters (*manual*).</p>
+ for example, parameters (*manual*).</p>
<p>The three Erlang (<c>.erl</c>) files in the messenger example are
individually compiled into object code file (<c>.beam</c>).
The Erlang system loads and links these files into the system
- when they are referred to during execution of the code. In our
- case we simply have put them in the same directory which is our
- current working directory (i.e. the place we have done "cd" to).
+ when they are referred to during execution of the code. In this
+ case, they are simply put in our current working directory
+ (that is, the place you have done "cd" to).
There are ways of putting the <c>.beam</c> files in other
directories.</p>
<p>In the messenger example, no assumptions have been made about
- what the message being sent is. It could be any valid Erlang term.</p>
+ what the message being sent is. It can be any valid Erlang term.</p>
</section>
</chapter>