Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/doc/!BobDoc/Data

Apple][e/PD/BOB/ARMBOB/doc/!BobDoc/Data

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras
Filename: Apple][e/PD/BOB/ARMBOB/doc/!BobDoc/Data
Read OK:
File size: 240D bytes
Load address: 0000
Exec address: 0000
File contents
<TITLE>ArmBob's datatypes</TITLE>
<H2>ArmBob's datatypes</H2>

As far as the programmer is concerned, all values in ArmBob programs
have one of the following types.
<UL>
<LI> <A HREF="#nil">NIL</A>
<LI> <A HREF="#integer">INTEGER</A>
<LI> <A HREF="#real">REAL</A>
<LI> <A HREF="#string">STRING</A>
<LI> <A HREF="#bytecode">BYTECODE</A>
<LI> <A HREF="#code">CODE</A>
<LI> <A HREF="#iostream">IOSTREAM</A>
<LI> <A HREF="#vector">VECTOR</A>
<LI> <A HREF="#object">OBJECT</A>
</UL>
These names are predefined as synonyms for the numerical codes
returned by the function <A HREF="Glossary#typeof"> <CODE>typeof</CODE> </A>.
What the numerical codes are is not important, except that NIL has
the value 0, and all other types have nonzero code.
<P>
Typing in ArmBob is implicit. Values carry their type around with them
and typechecking occurs at run time. There are no type declarations.
That is to say, types attach to values, not to variables or
expressions (apart from literal expressions).
<HR>
<H3><A NAME="nil">NIL</A></H3>
This type has only one value: <CODE> nil </CODE>. It is the
default value for unassigned variables, and for functions with
no <CODE> return </CODE> statement. As a conditional, 
<CODE> nil </CODE> counts as FALSE.

<H3><A NAME="integer">INTEGER</A></H3>
Integers must be in the range from -2147483648 to 2147483647. They
may also be used in hexadecimal form, with a &#39;&amp;&#39; as 
prefix, with lower case a,b,c,d,e,f denoting 10,11,12,13,14,15, 
in the range from &amp;00000000 to &amp;ffffffff. 
Characters are simply integers in the range 0-255. Single 
characters are enclosed in single forward quote characters 
<CODE> (&#39;) </CODE>.  So <CODE> &#39;A&#39; </CODE>
also denotes the integer 65, for example. 
The character <CODE> &#39;\&#39; </CODE> is used as an escape character, 
with <CODE> &#39;\n&#39;, &#39;\t&#39; </CODE> denoting the 
newline and tab characters. 

In conditional expressions, any nonzero integer is taken to represent 
truth, and zero or nil as falsity. TRUE is a synonym for 1 and FALSE 
is a synonym for 0. 

It is�also possible to use integers as addresses. 

<H3><A NAME="real">REAL</A></H3>
Single precision floating point numbers are characterised by the 
presence of a decimal point. Thus <CODE> x = 0; </CODE> will make 
<CODE> x </CODE> an integer, but <CODE> x = 0.0; </CODE> will make 
<CODE> x </CODE> a real. Reals can be multiplied or divided by
either reals or integers and the result is a real. So an integer can
be converted to a real by multiplying it by 1.0. 
You may not add or subtract a real with an integer. 

<H3><A NAME="string">STRING</A></H3>
Strings are arrays of bytes. They can be created either by a command
of the form <CODE><PRE>
        string_name = newstring(size); </CODE></PRE>
which creates a string of ASCII nulls, of size <CODE> size </CODE>, 
or by using literal strings. These are are enclosed in double quotes 
(&quot;) and may not contain the double quote character. 
The component characters of a string <CODE> s </CODE> are
<CODE><PRE>
              s[0], s[1], ........ s[sizeof(s)-1]
</PRE></CODE>
As in Basic, strings may be concatenated using the operators 
<CODE> + </CODE> and <CODE> += </CODE>. So <CODE> s += t </CODE>
is equivalent to <CODE> s = s + t </CODE>. In fact string handling 
in Armbob resembles Basic rather than C. The operator <CODE> + </CODE>
can also be used to add characters to strings. This operator 
associates to the left, so that
<CODE><PRE>
            33+33+&quot;&quot;
</PRE></CODE>
is the 1-element string <CODE> &quot;B&quot; </CODE>, while
<CODE><PRE>
            &quot;&quot;+33+33
</PRE></CODE>
is the 2-element string <CODE> &quot;!!&quot; </CODE>.
The function <CODE> val </CODE> will convert as much of a 
string into a number as it can. So 
<CODE> val(&quot; +10x&quot;) </CODE> and 
<CODE> val(&quot;&amp;a&quot;) </CODE> will both return 10.
The comparison operators work with strings as well as numbers,
and strings may be used after <CODE> case </CODE> in
<CODE> switch </CODE> structures.

<H3><A NAME="bytecode">BYTECODE</A></H3>
This is the type of user defined functions and methods.
These can only appear at the top level of a program.
Every program must have one function called <CODE>main</CODE>
defined. This determines the entry point for the program.
Functions can be the values of variables. Note that the parenthesized
list of formal parameters following the function name in a function
definition is not part of the function name itself. Functions can be 
returned as values of functions. E.g. <CODE><PRE>
      add(x,y) { return x+y; }
      mul(x,y) { return x*y; }
      main()
      { print(&quot;+/*?&quot;);
        print(((input() == &quot;*&quot;)?mul:add)(2,100),&quot;\n&quot;); }
</PRE></CODE>

<H3><A NAME="code">CODE</A></H3>
This is the type of built-in functions. Although built-in and user
defined functions are represented differently internally, and have
different types, in all other respects they behave the same way.

<H3><A NAME="iostream">IOSTREAM</A></H3>
The following function, to type out the contents of a file, illustrates
how iostreams are opened and closed.<CODE><PRE>

      typefile(filename)
      {
          local fp,c;
          if (fp = fopen(filename,&quot;r&quot;))
          {
              while ((c = getc(fp)) != EOF)
                  putc(c,stdout);
              fclose(fp);
          }
      }
</PRE></CODE> The iostreams
<A HREF="Glossary#stderr"> <CODE>stderr</CODE> </A>,
<A HREF="Glossary#stdin"> <CODE>stdin</CODE> </A>,
<A HREF="Glossary#stdout"> <CODE>stdout</CODE> </A>,
are built in. The following iostream handling functions are built in:
<A HREF="Glossary#fclose"> <CODE>fclose</CODE> </A>,
<A HREF="Glossary#fopen"> <CODE>fopen</CODE> </A>,
<A HREF="Glossary#getc"> <CODE>getc</CODE> </A>,
<A HREF="Glossary#putc"> <CODE>putc</CODE> </A>.
The expression <CODE> fp &lt;&lt; s </CODE> will output
the string <CODE> s </CODE> to iostream <CODE> fp </CODE>.
The value of this expression is <CODE> fp </CODE>, and 
<CODE> &lt;&lt; </CODE> associates to the left, so that
<CODE><PRE>
           fp &lt;&lt; s1 &lt;&lt; s2 .....
</PRE></CODE>
is equivalent to
<CODE><PRE>
           fp &lt;&lt; (s1 + s2 + ...... )
</PRE></CODE>

<H3><A NAME="vector">VECTOR</A></H3>
Vectors are arrays of fixed size. Their components can have any type.
In fact a vector can be one of its own components. Vectors allow one 
to construct complex datatypes.
They can be created by statements of the form
<CODE><PRE>
           v = newvector(size);
</PRE></CODE>
which creates a new vector with <CODE> size </CODE> components which are 
all <CODE> nil </CODE>. The components are
<CODE><PRE>
            v[0], .... , v[size-1]
</PRE></CODE>
Alternatively, the expression
<CODE><PRE>
           vector { <VAR>expr1</VAR>; ...... <VAR>exprn</VAR>; }
</PRE></CODE>
returns a new vector with components <VAR>expr1 ... exprn</VAR>. 
There must be at least one component and not more than 255 for 
this construction. Vectors have only one index. To define
matrices we could define
<CODE><PRE>
   newmatrix(m,n)
   {
    local matrix,i;
    matrix = newvector(m);
    for(i=0;i&lt;m;i++)
       matrix[i] = newvector(n);
    return matrix;
   }
</PRE></CODE>
and <CODE> matrix[i][j] </CODE> will be the element in the 
<CODE> i </CODE>-th row and <CODE> j </CODE>-th column.
This has the advantage that the <CODE> i </CODE>-th row is 
<CODE> matrix[i] </CODE>. When a vector is first created its 
components all have the value <CODE> nil </CODE>. We can replace
the numerical indices by names using the 
<A HREF="Glossary#enum> <CODE>enum </CODE> </A>
function. E.g.
<CODE><PRE>
          _3_vector = enum { x, y, z };
          v  = newvector(_3_vector);
          v[x] = v[y] = v[z] = 0.0;
</PRE></CODE>

<H3><A NAME="object">OBJECT</A></H3>
Following the conventions of C++, for every class one must define a
function with the same name as the class, to be used for creating
instance objects of the class. This function must exit with the
statement <CODE> return this; </CODE>. E.g.
<CODE><PRE>
      class person {age; name;}
<P>
      person::person(a,n)   // for creating new persons
      { age = a; name = n; return this;}
<P>
      person::has_age()     // for getting the age of a person
      { return age; }
<P>
      person::called()      // for getting the name of a person
      { return name; }
<P>
      person::older(y)      // for making a person age
      { age += y; }
<P>
      person::tell_age()    // tell how old someone is
      {
       stdout &lt;&lt; this->called()
              &lt;&lt; " is "
              &lt;&lt; this->has_age()
              &lt;&lt; " years old.\n" ;
       }
<P>
      main()
      {
       Fred = new person(30,"Fred");  // Fred is born 30 years old
       Fred->tell_age();
       Fred->older(10);               // he ages 10 years     
       Fred->tell_age();
      }
</PRE></CODE>
This example demonstrates the use of the all-important operators
<A HREF="Glossary#colon2"> <CODE>:: </CODE> </A> and
<A HREF="Glossary#arrow"> <CODE>-&gt; </CODE> </A> for defining
and using methods, and the keyword 
<A HREF="Glossary#new> <CODE>new </CODE> </A> for creating
instance objects.
00000000  3c 54 49 54 4c 45 3e 41  72 6d 42 6f 62 27 73 20  |<TITLE>ArmBob's |
00000010  64 61 74 61 74 79 70 65  73 3c 2f 54 49 54 4c 45  |datatypes</TITLE|
00000020  3e 0a 3c 48 32 3e 41 72  6d 42 6f 62 27 73 20 64  |>.<H2>ArmBob's d|
00000030  61 74 61 74 79 70 65 73  3c 2f 48 32 3e 0a 0a 41  |atatypes</H2>..A|
00000040  73 20 66 61 72 20 61 73  20 74 68 65 20 70 72 6f  |s far as the pro|
00000050  67 72 61 6d 6d 65 72 20  69 73 20 63 6f 6e 63 65  |grammer is conce|
00000060  72 6e 65 64 2c 20 61 6c  6c 20 76 61 6c 75 65 73  |rned, all values|
00000070  20 69 6e 20 41 72 6d 42  6f 62 20 70 72 6f 67 72  | in ArmBob progr|
00000080  61 6d 73 0a 68 61 76 65  20 6f 6e 65 20 6f 66 20  |ams.have one of |
00000090  74 68 65 20 66 6f 6c 6c  6f 77 69 6e 67 20 74 79  |the following ty|
000000a0  70 65 73 2e 0a 3c 55 4c  3e 0a 3c 4c 49 3e 20 3c  |pes..<UL>.<LI> <|
000000b0  41 20 48 52 45 46 3d 22  23 6e 69 6c 22 3e 4e 49  |A HREF="#nil">NI|
000000c0  4c 3c 2f 41 3e 0a 3c 4c  49 3e 20 3c 41 20 48 52  |L</A>.<LI> <A HR|
000000d0  45 46 3d 22 23 69 6e 74  65 67 65 72 22 3e 49 4e  |EF="#integer">IN|
000000e0  54 45 47 45 52 3c 2f 41  3e 0a 3c 4c 49 3e 20 3c  |TEGER</A>.<LI> <|
000000f0  41 20 48 52 45 46 3d 22  23 72 65 61 6c 22 3e 52  |A HREF="#real">R|
00000100  45 41 4c 3c 2f 41 3e 0a  3c 4c 49 3e 20 3c 41 20  |EAL</A>.<LI> <A |
00000110  48 52 45 46 3d 22 23 73  74 72 69 6e 67 22 3e 53  |HREF="#string">S|
00000120  54 52 49 4e 47 3c 2f 41  3e 0a 3c 4c 49 3e 20 3c  |TRING</A>.<LI> <|
00000130  41 20 48 52 45 46 3d 22  23 62 79 74 65 63 6f 64  |A HREF="#bytecod|
00000140  65 22 3e 42 59 54 45 43  4f 44 45 3c 2f 41 3e 0a  |e">BYTECODE</A>.|
00000150  3c 4c 49 3e 20 3c 41 20  48 52 45 46 3d 22 23 63  |<LI> <A HREF="#c|
00000160  6f 64 65 22 3e 43 4f 44  45 3c 2f 41 3e 0a 3c 4c  |ode">CODE</A>.<L|
00000170  49 3e 20 3c 41 20 48 52  45 46 3d 22 23 69 6f 73  |I> <A HREF="#ios|
00000180  74 72 65 61 6d 22 3e 49  4f 53 54 52 45 41 4d 3c  |tream">IOSTREAM<|
00000190  2f 41 3e 0a 3c 4c 49 3e  20 3c 41 20 48 52 45 46  |/A>.<LI> <A HREF|
000001a0  3d 22 23 76 65 63 74 6f  72 22 3e 56 45 43 54 4f  |="#vector">VECTO|
000001b0  52 3c 2f 41 3e 0a 3c 4c  49 3e 20 3c 41 20 48 52  |R</A>.<LI> <A HR|
000001c0  45 46 3d 22 23 6f 62 6a  65 63 74 22 3e 4f 42 4a  |EF="#object">OBJ|
000001d0  45 43 54 3c 2f 41 3e 0a  3c 2f 55 4c 3e 0a 54 68  |ECT</A>.</UL>.Th|
000001e0  65 73 65 20 6e 61 6d 65  73 20 61 72 65 20 70 72  |ese names are pr|
000001f0  65 64 65 66 69 6e 65 64  20 61 73 20 73 79 6e 6f  |edefined as syno|
00000200  6e 79 6d 73 20 66 6f 72  20 74 68 65 20 6e 75 6d  |nyms for the num|
00000210  65 72 69 63 61 6c 20 63  6f 64 65 73 0a 72 65 74  |erical codes.ret|
00000220  75 72 6e 65 64 20 62 79  20 74 68 65 20 66 75 6e  |urned by the fun|
00000230  63 74 69 6f 6e 20 3c 41  20 48 52 45 46 3d 22 47  |ction <A HREF="G|
00000240  6c 6f 73 73 61 72 79 23  74 79 70 65 6f 66 22 3e  |lossary#typeof">|
00000250  20 3c 43 4f 44 45 3e 74  79 70 65 6f 66 3c 2f 43  | <CODE>typeof</C|
00000260  4f 44 45 3e 20 3c 2f 41  3e 2e 0a 57 68 61 74 20  |ODE> </A>..What |
00000270  74 68 65 20 6e 75 6d 65  72 69 63 61 6c 20 63 6f  |the numerical co|
00000280  64 65 73 20 61 72 65 20  69 73 20 6e 6f 74 20 69  |des are is not i|
00000290  6d 70 6f 72 74 61 6e 74  2c 20 65 78 63 65 70 74  |mportant, except|
000002a0  20 74 68 61 74 20 4e 49  4c 20 68 61 73 0a 74 68  | that NIL has.th|
000002b0  65 20 76 61 6c 75 65 20  30 2c 20 61 6e 64 20 61  |e value 0, and a|
000002c0  6c 6c 20 6f 74 68 65 72  20 74 79 70 65 73 20 68  |ll other types h|
000002d0  61 76 65 20 6e 6f 6e 7a  65 72 6f 20 63 6f 64 65  |ave nonzero code|
000002e0  2e 0a 3c 50 3e 0a 54 79  70 69 6e 67 20 69 6e 20  |..<P>.Typing in |
000002f0  41 72 6d 42 6f 62 20 69  73 20 69 6d 70 6c 69 63  |ArmBob is implic|
00000300  69 74 2e 20 56 61 6c 75  65 73 20 63 61 72 72 79  |it. Values carry|
00000310  20 74 68 65 69 72 20 74  79 70 65 20 61 72 6f 75  | their type arou|
00000320  6e 64 20 77 69 74 68 20  74 68 65 6d 0a 61 6e 64  |nd with them.and|
00000330  20 74 79 70 65 63 68 65  63 6b 69 6e 67 20 6f 63  | typechecking oc|
00000340  63 75 72 73 20 61 74 20  72 75 6e 20 74 69 6d 65  |curs at run time|
00000350  2e 20 54 68 65 72 65 20  61 72 65 20 6e 6f 20 74  |. There are no t|
00000360  79 70 65 20 64 65 63 6c  61 72 61 74 69 6f 6e 73  |ype declarations|
00000370  2e 0a 54 68 61 74 20 69  73 20 74 6f 20 73 61 79  |..That is to say|
00000380  2c 20 74 79 70 65 73 20  61 74 74 61 63 68 20 74  |, types attach t|
00000390  6f 20 76 61 6c 75 65 73  2c 20 6e 6f 74 20 74 6f  |o values, not to|
000003a0  20 76 61 72 69 61 62 6c  65 73 20 6f 72 0a 65 78  | variables or.ex|
000003b0  70 72 65 73 73 69 6f 6e  73 20 28 61 70 61 72 74  |pressions (apart|
000003c0  20 66 72 6f 6d 20 6c 69  74 65 72 61 6c 20 65 78  | from literal ex|
000003d0  70 72 65 73 73 69 6f 6e  73 29 2e 0a 3c 48 52 3e  |pressions)..<HR>|
000003e0  0a 3c 48 33 3e 3c 41 20  4e 41 4d 45 3d 22 6e 69  |.<H3><A NAME="ni|
000003f0  6c 22 3e 4e 49 4c 3c 2f  41 3e 3c 2f 48 33 3e 0a  |l">NIL</A></H3>.|
00000400  54 68 69 73 20 74 79 70  65 20 68 61 73 20 6f 6e  |This type has on|
00000410  6c 79 20 6f 6e 65 20 76  61 6c 75 65 3a 20 3c 43  |ly one value: <C|
00000420  4f 44 45 3e 20 6e 69 6c  20 3c 2f 43 4f 44 45 3e  |ODE> nil </CODE>|
00000430  2e 20 49 74 20 69 73 20  74 68 65 0a 64 65 66 61  |. It is the.defa|
00000440  75 6c 74 20 76 61 6c 75  65 20 66 6f 72 20 75 6e  |ult value for un|
00000450  61 73 73 69 67 6e 65 64  20 76 61 72 69 61 62 6c  |assigned variabl|
00000460  65 73 2c 20 61 6e 64 20  66 6f 72 20 66 75 6e 63  |es, and for func|
00000470  74 69 6f 6e 73 20 77 69  74 68 0a 6e 6f 20 3c 43  |tions with.no <C|
00000480  4f 44 45 3e 20 72 65 74  75 72 6e 20 3c 2f 43 4f  |ODE> return </CO|
00000490  44 45 3e 20 73 74 61 74  65 6d 65 6e 74 2e 20 41  |DE> statement. A|
000004a0  73 20 61 20 63 6f 6e 64  69 74 69 6f 6e 61 6c 2c  |s a conditional,|
000004b0  20 0a 3c 43 4f 44 45 3e  20 6e 69 6c 20 3c 2f 43  | .<CODE> nil </C|
000004c0  4f 44 45 3e 20 63 6f 75  6e 74 73 20 61 73 20 46  |ODE> counts as F|
000004d0  41 4c 53 45 2e 0a 0a 3c  48 33 3e 3c 41 20 4e 41  |ALSE...<H3><A NA|
000004e0  4d 45 3d 22 69 6e 74 65  67 65 72 22 3e 49 4e 54  |ME="integer">INT|
000004f0  45 47 45 52 3c 2f 41 3e  3c 2f 48 33 3e 0a 49 6e  |EGER</A></H3>.In|
00000500  74 65 67 65 72 73 20 6d  75 73 74 20 62 65 20 69  |tegers must be i|
00000510  6e 20 74 68 65 20 72 61  6e 67 65 20 66 72 6f 6d  |n the range from|
00000520  20 2d 32 31 34 37 34 38  33 36 34 38 20 74 6f 20  | -2147483648 to |
00000530  32 31 34 37 34 38 33 36  34 37 2e 20 54 68 65 79  |2147483647. They|
00000540  0a 6d 61 79 20 61 6c 73  6f 20 62 65 20 75 73 65  |.may also be use|
00000550  64 20 69 6e 20 68 65 78  61 64 65 63 69 6d 61 6c  |d in hexadecimal|
00000560  20 66 6f 72 6d 2c 20 77  69 74 68 20 61 20 26 23  | form, with a &#|
00000570  33 39 3b 26 61 6d 70 3b  26 23 33 39 3b 20 61 73  |39;&amp;&#39; as|
00000580  20 0a 70 72 65 66 69 78  2c 20 77 69 74 68 20 6c  | .prefix, with l|
00000590  6f 77 65 72 20 63 61 73  65 20 61 2c 62 2c 63 2c  |ower case a,b,c,|
000005a0  64 2c 65 2c 66 20 64 65  6e 6f 74 69 6e 67 20 31  |d,e,f denoting 1|
000005b0  30 2c 31 31 2c 31 32 2c  31 33 2c 31 34 2c 31 35  |0,11,12,13,14,15|
000005c0  2c 20 0a 69 6e 20 74 68  65 20 72 61 6e 67 65 20  |, .in the range |
000005d0  66 72 6f 6d 20 26 61 6d  70 3b 30 30 30 30 30 30  |from &amp;000000|
000005e0  30 30 20 74 6f 20 26 61  6d 70 3b 66 66 66 66 66  |00 to &amp;fffff|
000005f0  66 66 66 2e 20 0a 43 68  61 72 61 63 74 65 72 73  |fff. .Characters|
00000600  20 61 72 65 20 73 69 6d  70 6c 79 20 69 6e 74 65  | are simply inte|
00000610  67 65 72 73 20 69 6e 20  74 68 65 20 72 61 6e 67  |gers in the rang|
00000620  65 20 30 2d 32 35 35 2e  20 53 69 6e 67 6c 65 20  |e 0-255. Single |
00000630  0a 63 68 61 72 61 63 74  65 72 73 20 61 72 65 20  |.characters are |
00000640  65 6e 63 6c 6f 73 65 64  20 69 6e 20 73 69 6e 67  |enclosed in sing|
00000650  6c 65 20 66 6f 72 77 61  72 64 20 71 75 6f 74 65  |le forward quote|
00000660  20 63 68 61 72 61 63 74  65 72 73 20 0a 3c 43 4f  | characters .<CO|
00000670  44 45 3e 20 28 26 23 33  39 3b 29 20 3c 2f 43 4f  |DE> (&#39;) </CO|
00000680  44 45 3e 2e 20 20 53 6f  20 3c 43 4f 44 45 3e 20  |DE>.  So <CODE> |
00000690  26 23 33 39 3b 41 26 23  33 39 3b 20 3c 2f 43 4f  |&#39;A&#39; </CO|
000006a0  44 45 3e 0a 61 6c 73 6f  20 64 65 6e 6f 74 65 73  |DE>.also denotes|
000006b0  20 74 68 65 20 69 6e 74  65 67 65 72 20 36 35 2c  | the integer 65,|
000006c0  20 66 6f 72 20 65 78 61  6d 70 6c 65 2e 20 0a 54  | for example. .T|
000006d0  68 65 20 63 68 61 72 61  63 74 65 72 20 3c 43 4f  |he character <CO|
000006e0  44 45 3e 20 26 23 33 39  3b 5c 26 23 33 39 3b 20  |DE> &#39;\&#39; |
000006f0  3c 2f 43 4f 44 45 3e 20  69 73 20 75 73 65 64 20  |</CODE> is used |
00000700  61 73 20 61 6e 20 65 73  63 61 70 65 20 63 68 61  |as an escape cha|
00000710  72 61 63 74 65 72 2c 20  0a 77 69 74 68 20 3c 43  |racter, .with <C|
00000720  4f 44 45 3e 20 26 23 33  39 3b 5c 6e 26 23 33 39  |ODE> &#39;\n&#39|
00000730  3b 2c 20 26 23 33 39 3b  5c 74 26 23 33 39 3b 20  |;, &#39;\t&#39; |
00000740  3c 2f 43 4f 44 45 3e 20  64 65 6e 6f 74 69 6e 67  |</CODE> denoting|
00000750  20 74 68 65 20 0a 6e 65  77 6c 69 6e 65 20 61 6e  | the .newline an|
00000760  64 20 74 61 62 20 63 68  61 72 61 63 74 65 72 73  |d tab characters|
00000770  2e 20 0a 0a 49 6e 20 63  6f 6e 64 69 74 69 6f 6e  |. ..In condition|
00000780  61 6c 20 65 78 70 72 65  73 73 69 6f 6e 73 2c 20  |al expressions, |
00000790  61 6e 79 20 6e 6f 6e 7a  65 72 6f 20 69 6e 74 65  |any nonzero inte|
000007a0  67 65 72 20 69 73 20 74  61 6b 65 6e 20 74 6f 20  |ger is taken to |
000007b0  72 65 70 72 65 73 65 6e  74 20 0a 74 72 75 74 68  |represent .truth|
000007c0  2c 20 61 6e 64 20 7a 65  72 6f 20 6f 72 20 6e 69  |, and zero or ni|
000007d0  6c 20 61 73 20 66 61 6c  73 69 74 79 2e 20 54 52  |l as falsity. TR|
000007e0  55 45 20 69 73 20 61 20  73 79 6e 6f 6e 79 6d 20  |UE is a synonym |
000007f0  66 6f 72 20 31 20 61 6e  64 20 46 41 4c 53 45 20  |for 1 and FALSE |
00000800  0a 69 73 20 61 20 73 79  6e 6f 6e 79 6d 20 66 6f  |.is a synonym fo|
00000810  72 20 30 2e 20 0a 0a 49  74 20 69 73 a0 61 6c 73  |r 0. ..It is.als|
00000820  6f 20 70 6f 73 73 69 62  6c 65 20 74 6f 20 75 73  |o possible to us|
00000830  65 20 69 6e 74 65 67 65  72 73 20 61 73 20 61 64  |e integers as ad|
00000840  64 72 65 73 73 65 73 2e  20 0a 0a 3c 48 33 3e 3c  |dresses. ..<H3><|
00000850  41 20 4e 41 4d 45 3d 22  72 65 61 6c 22 3e 52 45  |A NAME="real">RE|
00000860  41 4c 3c 2f 41 3e 3c 2f  48 33 3e 0a 53 69 6e 67  |AL</A></H3>.Sing|
00000870  6c 65 20 70 72 65 63 69  73 69 6f 6e 20 66 6c 6f  |le precision flo|
00000880  61 74 69 6e 67 20 70 6f  69 6e 74 20 6e 75 6d 62  |ating point numb|
00000890  65 72 73 20 61 72 65 20  63 68 61 72 61 63 74 65  |ers are characte|
000008a0  72 69 73 65 64 20 62 79  20 74 68 65 20 0a 70 72  |rised by the .pr|
000008b0  65 73 65 6e 63 65 20 6f  66 20 61 20 64 65 63 69  |esence of a deci|
000008c0  6d 61 6c 20 70 6f 69 6e  74 2e 20 54 68 75 73 20  |mal point. Thus |
000008d0  3c 43 4f 44 45 3e 20 78  20 3d 20 30 3b 20 3c 2f  |<CODE> x = 0; </|
000008e0  43 4f 44 45 3e 20 77 69  6c 6c 20 6d 61 6b 65 20  |CODE> will make |
000008f0  0a 3c 43 4f 44 45 3e 20  78 20 3c 2f 43 4f 44 45  |.<CODE> x </CODE|
00000900  3e 20 61 6e 20 69 6e 74  65 67 65 72 2c 20 62 75  |> an integer, bu|
00000910  74 20 3c 43 4f 44 45 3e  20 78 20 3d 20 30 2e 30  |t <CODE> x = 0.0|
00000920  3b 20 3c 2f 43 4f 44 45  3e 20 77 69 6c 6c 20 6d  |; </CODE> will m|
00000930  61 6b 65 20 0a 3c 43 4f  44 45 3e 20 78 20 3c 2f  |ake .<CODE> x </|
00000940  43 4f 44 45 3e 20 61 20  72 65 61 6c 2e 20 52 65  |CODE> a real. Re|
00000950  61 6c 73 20 63 61 6e 20  62 65 20 6d 75 6c 74 69  |als can be multi|
00000960  70 6c 69 65 64 20 6f 72  20 64 69 76 69 64 65 64  |plied or divided|
00000970  20 62 79 0a 65 69 74 68  65 72 20 72 65 61 6c 73  | by.either reals|
00000980  20 6f 72 20 69 6e 74 65  67 65 72 73 20 61 6e 64  | or integers and|
00000990  20 74 68 65 20 72 65 73  75 6c 74 20 69 73 20 61  | the result is a|
000009a0  20 72 65 61 6c 2e 20 53  6f 20 61 6e 20 69 6e 74  | real. So an int|
000009b0  65 67 65 72 20 63 61 6e  0a 62 65 20 63 6f 6e 76  |eger can.be conv|
000009c0  65 72 74 65 64 20 74 6f  20 61 20 72 65 61 6c 20  |erted to a real |
000009d0  62 79 20 6d 75 6c 74 69  70 6c 79 69 6e 67 20 69  |by multiplying i|
000009e0  74 20 62 79 20 31 2e 30  2e 20 0a 59 6f 75 20 6d  |t by 1.0. .You m|
000009f0  61 79 20 6e 6f 74 20 61  64 64 20 6f 72 20 73 75  |ay not add or su|
00000a00  62 74 72 61 63 74 20 61  20 72 65 61 6c 20 77 69  |btract a real wi|
00000a10  74 68 20 61 6e 20 69 6e  74 65 67 65 72 2e 20 0a  |th an integer. .|
00000a20  0a 3c 48 33 3e 3c 41 20  4e 41 4d 45 3d 22 73 74  |.<H3><A NAME="st|
00000a30  72 69 6e 67 22 3e 53 54  52 49 4e 47 3c 2f 41 3e  |ring">STRING</A>|
00000a40  3c 2f 48 33 3e 0a 53 74  72 69 6e 67 73 20 61 72  |</H3>.Strings ar|
00000a50  65 20 61 72 72 61 79 73  20 6f 66 20 62 79 74 65  |e arrays of byte|
00000a60  73 2e 20 54 68 65 79 20  63 61 6e 20 62 65 20 63  |s. They can be c|
00000a70  72 65 61 74 65 64 20 65  69 74 68 65 72 20 62 79  |reated either by|
00000a80  20 61 20 63 6f 6d 6d 61  6e 64 0a 6f 66 20 74 68  | a command.of th|
00000a90  65 20 66 6f 72 6d 20 3c  43 4f 44 45 3e 3c 50 52  |e form <CODE><PR|
00000aa0  45 3e 0a 20 20 20 20 20  20 20 20 73 74 72 69 6e  |E>.        strin|
00000ab0  67 5f 6e 61 6d 65 20 3d  20 6e 65 77 73 74 72 69  |g_name = newstri|
00000ac0  6e 67 28 73 69 7a 65 29  3b 20 3c 2f 43 4f 44 45  |ng(size); </CODE|
00000ad0  3e 3c 2f 50 52 45 3e 0a  77 68 69 63 68 20 63 72  |></PRE>.which cr|
00000ae0  65 61 74 65 73 20 61 20  73 74 72 69 6e 67 20 6f  |eates a string o|
00000af0  66 20 41 53 43 49 49 20  6e 75 6c 6c 73 2c 20 6f  |f ASCII nulls, o|
00000b00  66 20 73 69 7a 65 20 3c  43 4f 44 45 3e 20 73 69  |f size <CODE> si|
00000b10  7a 65 20 3c 2f 43 4f 44  45 3e 2c 20 0a 6f 72 20  |ze </CODE>, .or |
00000b20  62 79 20 75 73 69 6e 67  20 6c 69 74 65 72 61 6c  |by using literal|
00000b30  20 73 74 72 69 6e 67 73  2e 20 54 68 65 73 65 20  | strings. These |
00000b40  61 72 65 20 61 72 65 20  65 6e 63 6c 6f 73 65 64  |are are enclosed|
00000b50  20 69 6e 20 64 6f 75 62  6c 65 20 71 75 6f 74 65  | in double quote|
00000b60  73 20 0a 28 26 71 75 6f  74 3b 29 20 61 6e 64 20  |s .(&quot;) and |
00000b70  6d 61 79 20 6e 6f 74 20  63 6f 6e 74 61 69 6e 20  |may not contain |
00000b80  74 68 65 20 64 6f 75 62  6c 65 20 71 75 6f 74 65  |the double quote|
00000b90  20 63 68 61 72 61 63 74  65 72 2e 20 0a 54 68 65  | character. .The|
00000ba0  20 63 6f 6d 70 6f 6e 65  6e 74 20 63 68 61 72 61  | component chara|
00000bb0  63 74 65 72 73 20 6f 66  20 61 20 73 74 72 69 6e  |cters of a strin|
00000bc0  67 20 3c 43 4f 44 45 3e  20 73 20 3c 2f 43 4f 44  |g <CODE> s </COD|
00000bd0  45 3e 20 61 72 65 0a 3c  43 4f 44 45 3e 3c 50 52  |E> are.<CODE><PR|
00000be0  45 3e 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |E>.             |
00000bf0  20 73 5b 30 5d 2c 20 73  5b 31 5d 2c 20 2e 2e 2e  | s[0], s[1], ...|
00000c00  2e 2e 2e 2e 2e 20 73 5b  73 69 7a 65 6f 66 28 73  |..... s[sizeof(s|
00000c10  29 2d 31 5d 0a 3c 2f 50  52 45 3e 3c 2f 43 4f 44  |)-1].</PRE></COD|
00000c20  45 3e 0a 41 73 20 69 6e  20 42 61 73 69 63 2c 20  |E>.As in Basic, |
00000c30  73 74 72 69 6e 67 73 20  6d 61 79 20 62 65 20 63  |strings may be c|
00000c40  6f 6e 63 61 74 65 6e 61  74 65 64 20 75 73 69 6e  |oncatenated usin|
00000c50  67 20 74 68 65 20 6f 70  65 72 61 74 6f 72 73 20  |g the operators |
00000c60  0a 3c 43 4f 44 45 3e 20  2b 20 3c 2f 43 4f 44 45  |.<CODE> + </CODE|
00000c70  3e 20 61 6e 64 20 3c 43  4f 44 45 3e 20 2b 3d 20  |> and <CODE> += |
00000c80  3c 2f 43 4f 44 45 3e 2e  20 53 6f 20 3c 43 4f 44  |</CODE>. So <COD|
00000c90  45 3e 20 73 20 2b 3d 20  74 20 3c 2f 43 4f 44 45  |E> s += t </CODE|
00000ca0  3e 0a 69 73 20 65 71 75  69 76 61 6c 65 6e 74 20  |>.is equivalent |
00000cb0  74 6f 20 3c 43 4f 44 45  3e 20 73 20 3d 20 73 20  |to <CODE> s = s |
00000cc0  2b 20 74 20 3c 2f 43 4f  44 45 3e 2e 20 49 6e 20  |+ t </CODE>. In |
00000cd0  66 61 63 74 20 73 74 72  69 6e 67 20 68 61 6e 64  |fact string hand|
00000ce0  6c 69 6e 67 20 0a 69 6e  20 41 72 6d 62 6f 62 20  |ling .in Armbob |
00000cf0  72 65 73 65 6d 62 6c 65  73 20 42 61 73 69 63 20  |resembles Basic |
00000d00  72 61 74 68 65 72 20 74  68 61 6e 20 43 2e 20 54  |rather than C. T|
00000d10  68 65 20 6f 70 65 72 61  74 6f 72 20 3c 43 4f 44  |he operator <COD|
00000d20  45 3e 20 2b 20 3c 2f 43  4f 44 45 3e 0a 63 61 6e  |E> + </CODE>.can|
00000d30  20 61 6c 73 6f 20 62 65  20 75 73 65 64 20 74 6f  | also be used to|
00000d40  20 61 64 64 20 63 68 61  72 61 63 74 65 72 73 20  | add characters |
00000d50  74 6f 20 73 74 72 69 6e  67 73 2e 20 54 68 69 73  |to strings. This|
00000d60  20 6f 70 65 72 61 74 6f  72 20 0a 61 73 73 6f 63  | operator .assoc|
00000d70  69 61 74 65 73 20 74 6f  20 74 68 65 20 6c 65 66  |iates to the lef|
00000d80  74 2c 20 73 6f 20 74 68  61 74 0a 3c 43 4f 44 45  |t, so that.<CODE|
00000d90  3e 3c 50 52 45 3e 0a 20  20 20 20 20 20 20 20 20  |><PRE>.         |
00000da0  20 20 20 33 33 2b 33 33  2b 26 71 75 6f 74 3b 26  |   33+33+&quot;&|
00000db0  71 75 6f 74 3b 0a 3c 2f  50 52 45 3e 3c 2f 43 4f  |quot;.</PRE></CO|
00000dc0  44 45 3e 0a 69 73 20 74  68 65 20 31 2d 65 6c 65  |DE>.is the 1-ele|
00000dd0  6d 65 6e 74 20 73 74 72  69 6e 67 20 3c 43 4f 44  |ment string <COD|
00000de0  45 3e 20 26 71 75 6f 74  3b 42 26 71 75 6f 74 3b  |E> &quot;B&quot;|
00000df0  20 3c 2f 43 4f 44 45 3e  2c 20 77 68 69 6c 65 0a  | </CODE>, while.|
00000e00  3c 43 4f 44 45 3e 3c 50  52 45 3e 0a 20 20 20 20  |<CODE><PRE>.    |
00000e10  20 20 20 20 20 20 20 20  26 71 75 6f 74 3b 26 71  |        &quot;&q|
00000e20  75 6f 74 3b 2b 33 33 2b  33 33 0a 3c 2f 50 52 45  |uot;+33+33.</PRE|
00000e30  3e 3c 2f 43 4f 44 45 3e  0a 69 73 20 74 68 65 20  |></CODE>.is the |
00000e40  32 2d 65 6c 65 6d 65 6e  74 20 73 74 72 69 6e 67  |2-element string|
00000e50  20 3c 43 4f 44 45 3e 20  26 71 75 6f 74 3b 21 21  | <CODE> &quot;!!|
00000e60  26 71 75 6f 74 3b 20 3c  2f 43 4f 44 45 3e 2e 0a  |&quot; </CODE>..|
00000e70  54 68 65 20 66 75 6e 63  74 69 6f 6e 20 3c 43 4f  |The function <CO|
00000e80  44 45 3e 20 76 61 6c 20  3c 2f 43 4f 44 45 3e 20  |DE> val </CODE> |
00000e90  77 69 6c 6c 20 63 6f 6e  76 65 72 74 20 61 73 20  |will convert as |
00000ea0  6d 75 63 68 20 6f 66 20  61 20 0a 73 74 72 69 6e  |much of a .strin|
00000eb0  67 20 69 6e 74 6f 20 61  20 6e 75 6d 62 65 72 20  |g into a number |
00000ec0  61 73 20 69 74 20 63 61  6e 2e 20 53 6f 20 0a 3c  |as it can. So .<|
00000ed0  43 4f 44 45 3e 20 76 61  6c 28 26 71 75 6f 74 3b  |CODE> val(&quot;|
00000ee0  20 2b 31 30 78 26 71 75  6f 74 3b 29 20 3c 2f 43  | +10x&quot;) </C|
00000ef0  4f 44 45 3e 20 61 6e 64  20 0a 3c 43 4f 44 45 3e  |ODE> and .<CODE>|
00000f00  20 76 61 6c 28 26 71 75  6f 74 3b 26 61 6d 70 3b  | val(&quot;&amp;|
00000f10  61 26 71 75 6f 74 3b 29  20 3c 2f 43 4f 44 45 3e  |a&quot;) </CODE>|
00000f20  20 77 69 6c 6c 20 62 6f  74 68 20 72 65 74 75 72  | will both retur|
00000f30  6e 20 31 30 2e 0a 54 68  65 20 63 6f 6d 70 61 72  |n 10..The compar|
00000f40  69 73 6f 6e 20 6f 70 65  72 61 74 6f 72 73 20 77  |ison operators w|
00000f50  6f 72 6b 20 77 69 74 68  20 73 74 72 69 6e 67 73  |ork with strings|
00000f60  20 61 73 20 77 65 6c 6c  20 61 73 20 6e 75 6d 62  | as well as numb|
00000f70  65 72 73 2c 0a 61 6e 64  20 73 74 72 69 6e 67 73  |ers,.and strings|
00000f80  20 6d 61 79 20 62 65 20  75 73 65 64 20 61 66 74  | may be used aft|
00000f90  65 72 20 3c 43 4f 44 45  3e 20 63 61 73 65 20 3c  |er <CODE> case <|
00000fa0  2f 43 4f 44 45 3e 20 69  6e 0a 3c 43 4f 44 45 3e  |/CODE> in.<CODE>|
00000fb0  20 73 77 69 74 63 68 20  3c 2f 43 4f 44 45 3e 20  | switch </CODE> |
00000fc0  73 74 72 75 63 74 75 72  65 73 2e 0a 0a 3c 48 33  |structures...<H3|
00000fd0  3e 3c 41 20 4e 41 4d 45  3d 22 62 79 74 65 63 6f  |><A NAME="byteco|
00000fe0  64 65 22 3e 42 59 54 45  43 4f 44 45 3c 2f 41 3e  |de">BYTECODE</A>|
00000ff0  3c 2f 48 33 3e 0a 54 68  69 73 20 69 73 20 74 68  |</H3>.This is th|
00001000  65 20 74 79 70 65 20 6f  66 20 75 73 65 72 20 64  |e type of user d|
00001010  65 66 69 6e 65 64 20 66  75 6e 63 74 69 6f 6e 73  |efined functions|
00001020  20 61 6e 64 20 6d 65 74  68 6f 64 73 2e 0a 54 68  | and methods..Th|
00001030  65 73 65 20 63 61 6e 20  6f 6e 6c 79 20 61 70 70  |ese can only app|
00001040  65 61 72 20 61 74 20 74  68 65 20 74 6f 70 20 6c  |ear at the top l|
00001050  65 76 65 6c 20 6f 66 20  61 20 70 72 6f 67 72 61  |evel of a progra|
00001060  6d 2e 0a 45 76 65 72 79  20 70 72 6f 67 72 61 6d  |m..Every program|
00001070  20 6d 75 73 74 20 68 61  76 65 20 6f 6e 65 20 66  | must have one f|
00001080  75 6e 63 74 69 6f 6e 20  63 61 6c 6c 65 64 20 3c  |unction called <|
00001090  43 4f 44 45 3e 6d 61 69  6e 3c 2f 43 4f 44 45 3e  |CODE>main</CODE>|
000010a0  0a 64 65 66 69 6e 65 64  2e 20 54 68 69 73 20 64  |.defined. This d|
000010b0  65 74 65 72 6d 69 6e 65  73 20 74 68 65 20 65 6e  |etermines the en|
000010c0  74 72 79 20 70 6f 69 6e  74 20 66 6f 72 20 74 68  |try point for th|
000010d0  65 20 70 72 6f 67 72 61  6d 2e 0a 46 75 6e 63 74  |e program..Funct|
000010e0  69 6f 6e 73 20 63 61 6e  20 62 65 20 74 68 65 20  |ions can be the |
000010f0  76 61 6c 75 65 73 20 6f  66 20 76 61 72 69 61 62  |values of variab|
00001100  6c 65 73 2e 20 4e 6f 74  65 20 74 68 61 74 20 74  |les. Note that t|
00001110  68 65 20 70 61 72 65 6e  74 68 65 73 69 7a 65 64  |he parenthesized|
00001120  0a 6c 69 73 74 20 6f 66  20 66 6f 72 6d 61 6c 20  |.list of formal |
00001130  70 61 72 61 6d 65 74 65  72 73 20 66 6f 6c 6c 6f  |parameters follo|
00001140  77 69 6e 67 20 74 68 65  20 66 75 6e 63 74 69 6f  |wing the functio|
00001150  6e 20 6e 61 6d 65 20 69  6e 20 61 20 66 75 6e 63  |n name in a func|
00001160  74 69 6f 6e 0a 64 65 66  69 6e 69 74 69 6f 6e 20  |tion.definition |
00001170  69 73 20 6e 6f 74 20 70  61 72 74 20 6f 66 20 74  |is not part of t|
00001180  68 65 20 66 75 6e 63 74  69 6f 6e 20 6e 61 6d 65  |he function name|
00001190  20 69 74 73 65 6c 66 2e  20 46 75 6e 63 74 69 6f  | itself. Functio|
000011a0  6e 73 20 63 61 6e 20 62  65 20 0a 72 65 74 75 72  |ns can be .retur|
000011b0  6e 65 64 20 61 73 20 76  61 6c 75 65 73 20 6f 66  |ned as values of|
000011c0  20 66 75 6e 63 74 69 6f  6e 73 2e 20 45 2e 67 2e  | functions. E.g.|
000011d0  20 3c 43 4f 44 45 3e 3c  50 52 45 3e 0a 20 20 20  | <CODE><PRE>.   |
000011e0  20 20 20 61 64 64 28 78  2c 79 29 20 7b 20 72 65  |   add(x,y) { re|
000011f0  74 75 72 6e 20 78 2b 79  3b 20 7d 0a 20 20 20 20  |turn x+y; }.    |
00001200  20 20 6d 75 6c 28 78 2c  79 29 20 7b 20 72 65 74  |  mul(x,y) { ret|
00001210  75 72 6e 20 78 2a 79 3b  20 7d 0a 20 20 20 20 20  |urn x*y; }.     |
00001220  20 6d 61 69 6e 28 29 0a  20 20 20 20 20 20 7b 20  | main().      { |
00001230  70 72 69 6e 74 28 26 71  75 6f 74 3b 2b 2f 2a 3f  |print(&quot;+/*?|
00001240  26 71 75 6f 74 3b 29 3b  0a 20 20 20 20 20 20 20  |&quot;);.       |
00001250  20 70 72 69 6e 74 28 28  28 69 6e 70 75 74 28 29  | print(((input()|
00001260  20 3d 3d 20 26 71 75 6f  74 3b 2a 26 71 75 6f 74  | == &quot;*&quot|
00001270  3b 29 3f 6d 75 6c 3a 61  64 64 29 28 32 2c 31 30  |;)?mul:add)(2,10|
00001280  30 29 2c 26 71 75 6f 74  3b 5c 6e 26 71 75 6f 74  |0),&quot;\n&quot|
00001290  3b 29 3b 20 7d 0a 3c 2f  50 52 45 3e 3c 2f 43 4f  |;); }.</PRE></CO|
000012a0  44 45 3e 0a 0a 3c 48 33  3e 3c 41 20 4e 41 4d 45  |DE>..<H3><A NAME|
000012b0  3d 22 63 6f 64 65 22 3e  43 4f 44 45 3c 2f 41 3e  |="code">CODE</A>|
000012c0  3c 2f 48 33 3e 0a 54 68  69 73 20 69 73 20 74 68  |</H3>.This is th|
000012d0  65 20 74 79 70 65 20 6f  66 20 62 75 69 6c 74 2d  |e type of built-|
000012e0  69 6e 20 66 75 6e 63 74  69 6f 6e 73 2e 20 41 6c  |in functions. Al|
000012f0  74 68 6f 75 67 68 20 62  75 69 6c 74 2d 69 6e 20  |though built-in |
00001300  61 6e 64 20 75 73 65 72  0a 64 65 66 69 6e 65 64  |and user.defined|
00001310  20 66 75 6e 63 74 69 6f  6e 73 20 61 72 65 20 72  | functions are r|
00001320  65 70 72 65 73 65 6e 74  65 64 20 64 69 66 66 65  |epresented diffe|
00001330  72 65 6e 74 6c 79 20 69  6e 74 65 72 6e 61 6c 6c  |rently internall|
00001340  79 2c 20 61 6e 64 20 68  61 76 65 0a 64 69 66 66  |y, and have.diff|
00001350  65 72 65 6e 74 20 74 79  70 65 73 2c 20 69 6e 20  |erent types, in |
00001360  61 6c 6c 20 6f 74 68 65  72 20 72 65 73 70 65 63  |all other respec|
00001370  74 73 20 74 68 65 79 20  62 65 68 61 76 65 20 74  |ts they behave t|
00001380  68 65 20 73 61 6d 65 20  77 61 79 2e 0a 0a 3c 48  |he same way...<H|
00001390  33 3e 3c 41 20 4e 41 4d  45 3d 22 69 6f 73 74 72  |3><A NAME="iostr|
000013a0  65 61 6d 22 3e 49 4f 53  54 52 45 41 4d 3c 2f 41  |eam">IOSTREAM</A|
000013b0  3e 3c 2f 48 33 3e 0a 54  68 65 20 66 6f 6c 6c 6f  |></H3>.The follo|
000013c0  77 69 6e 67 20 66 75 6e  63 74 69 6f 6e 2c 20 74  |wing function, t|
000013d0  6f 20 74 79 70 65 20 6f  75 74 20 74 68 65 20 63  |o type out the c|
000013e0  6f 6e 74 65 6e 74 73 20  6f 66 20 61 20 66 69 6c  |ontents of a fil|
000013f0  65 2c 20 69 6c 6c 75 73  74 72 61 74 65 73 0a 68  |e, illustrates.h|
00001400  6f 77 20 69 6f 73 74 72  65 61 6d 73 20 61 72 65  |ow iostreams are|
00001410  20 6f 70 65 6e 65 64 20  61 6e 64 20 63 6c 6f 73  | opened and clos|
00001420  65 64 2e 3c 43 4f 44 45  3e 3c 50 52 45 3e 0a 0a  |ed.<CODE><PRE>..|
00001430  20 20 20 20 20 20 74 79  70 65 66 69 6c 65 28 66  |      typefile(f|
00001440  69 6c 65 6e 61 6d 65 29  0a 20 20 20 20 20 20 7b  |ilename).      {|
00001450  0a 20 20 20 20 20 20 20  20 20 20 6c 6f 63 61 6c  |.          local|
00001460  20 66 70 2c 63 3b 0a 20  20 20 20 20 20 20 20 20  | fp,c;.         |
00001470  20 69 66 20 28 66 70 20  3d 20 66 6f 70 65 6e 28  | if (fp = fopen(|
00001480  66 69 6c 65 6e 61 6d 65  2c 26 71 75 6f 74 3b 72  |filename,&quot;r|
00001490  26 71 75 6f 74 3b 29 29  0a 20 20 20 20 20 20 20  |&quot;)).       |
000014a0  20 20 20 7b 0a 20 20 20  20 20 20 20 20 20 20 20  |   {.           |
000014b0  20 20 20 77 68 69 6c 65  20 28 28 63 20 3d 20 67  |   while ((c = g|
000014c0  65 74 63 28 66 70 29 29  20 21 3d 20 45 4f 46 29  |etc(fp)) != EOF)|
000014d0  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
000014e0  20 20 20 70 75 74 63 28  63 2c 73 74 64 6f 75 74  |   putc(c,stdout|
000014f0  29 3b 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |);.             |
00001500  20 66 63 6c 6f 73 65 28  66 70 29 3b 0a 20 20 20  | fclose(fp);.   |
00001510  20 20 20 20 20 20 20 7d  0a 20 20 20 20 20 20 7d  |       }.      }|
00001520  0a 3c 2f 50 52 45 3e 3c  2f 43 4f 44 45 3e 20 54  |.</PRE></CODE> T|
00001530  68 65 20 69 6f 73 74 72  65 61 6d 73 0a 3c 41 20  |he iostreams.<A |
00001540  48 52 45 46 3d 22 47 6c  6f 73 73 61 72 79 23 73  |HREF="Glossary#s|
00001550  74 64 65 72 72 22 3e 20  3c 43 4f 44 45 3e 73 74  |tderr"> <CODE>st|
00001560  64 65 72 72 3c 2f 43 4f  44 45 3e 20 3c 2f 41 3e  |derr</CODE> </A>|
00001570  2c 0a 3c 41 20 48 52 45  46 3d 22 47 6c 6f 73 73  |,.<A HREF="Gloss|
00001580  61 72 79 23 73 74 64 69  6e 22 3e 20 3c 43 4f 44  |ary#stdin"> <COD|
00001590  45 3e 73 74 64 69 6e 3c  2f 43 4f 44 45 3e 20 3c  |E>stdin</CODE> <|
000015a0  2f 41 3e 2c 0a 3c 41 20  48 52 45 46 3d 22 47 6c  |/A>,.<A HREF="Gl|
000015b0  6f 73 73 61 72 79 23 73  74 64 6f 75 74 22 3e 20  |ossary#stdout"> |
000015c0  3c 43 4f 44 45 3e 73 74  64 6f 75 74 3c 2f 43 4f  |<CODE>stdout</CO|
000015d0  44 45 3e 20 3c 2f 41 3e  2c 0a 61 72 65 20 62 75  |DE> </A>,.are bu|
000015e0  69 6c 74 20 69 6e 2e 20  54 68 65 20 66 6f 6c 6c  |ilt in. The foll|
000015f0  6f 77 69 6e 67 20 69 6f  73 74 72 65 61 6d 20 68  |owing iostream h|
00001600  61 6e 64 6c 69 6e 67 20  66 75 6e 63 74 69 6f 6e  |andling function|
00001610  73 20 61 72 65 20 62 75  69 6c 74 20 69 6e 3a 0a  |s are built in:.|
00001620  3c 41 20 48 52 45 46 3d  22 47 6c 6f 73 73 61 72  |<A HREF="Glossar|
00001630  79 23 66 63 6c 6f 73 65  22 3e 20 3c 43 4f 44 45  |y#fclose"> <CODE|
00001640  3e 66 63 6c 6f 73 65 3c  2f 43 4f 44 45 3e 20 3c  |>fclose</CODE> <|
00001650  2f 41 3e 2c 0a 3c 41 20  48 52 45 46 3d 22 47 6c  |/A>,.<A HREF="Gl|
00001660  6f 73 73 61 72 79 23 66  6f 70 65 6e 22 3e 20 3c  |ossary#fopen"> <|
00001670  43 4f 44 45 3e 66 6f 70  65 6e 3c 2f 43 4f 44 45  |CODE>fopen</CODE|
00001680  3e 20 3c 2f 41 3e 2c 0a  3c 41 20 48 52 45 46 3d  |> </A>,.<A HREF=|
00001690  22 47 6c 6f 73 73 61 72  79 23 67 65 74 63 22 3e  |"Glossary#getc">|
000016a0  20 3c 43 4f 44 45 3e 67  65 74 63 3c 2f 43 4f 44  | <CODE>getc</COD|
000016b0  45 3e 20 3c 2f 41 3e 2c  0a 3c 41 20 48 52 45 46  |E> </A>,.<A HREF|
000016c0  3d 22 47 6c 6f 73 73 61  72 79 23 70 75 74 63 22  |="Glossary#putc"|
000016d0  3e 20 3c 43 4f 44 45 3e  70 75 74 63 3c 2f 43 4f  |> <CODE>putc</CO|
000016e0  44 45 3e 20 3c 2f 41 3e  2e 0a 54 68 65 20 65 78  |DE> </A>..The ex|
000016f0  70 72 65 73 73 69 6f 6e  20 3c 43 4f 44 45 3e 20  |pression <CODE> |
00001700  66 70 20 26 6c 74 3b 26  6c 74 3b 20 73 20 3c 2f  |fp &lt;&lt; s </|
00001710  43 4f 44 45 3e 20 77 69  6c 6c 20 6f 75 74 70 75  |CODE> will outpu|
00001720  74 0a 74 68 65 20 73 74  72 69 6e 67 20 3c 43 4f  |t.the string <CO|
00001730  44 45 3e 20 73 20 3c 2f  43 4f 44 45 3e 20 74 6f  |DE> s </CODE> to|
00001740  20 69 6f 73 74 72 65 61  6d 20 3c 43 4f 44 45 3e  | iostream <CODE>|
00001750  20 66 70 20 3c 2f 43 4f  44 45 3e 2e 0a 54 68 65  | fp </CODE>..The|
00001760  20 76 61 6c 75 65 20 6f  66 20 74 68 69 73 20 65  | value of this e|
00001770  78 70 72 65 73 73 69 6f  6e 20 69 73 20 3c 43 4f  |xpression is <CO|
00001780  44 45 3e 20 66 70 20 3c  2f 43 4f 44 45 3e 2c 20  |DE> fp </CODE>, |
00001790  61 6e 64 20 0a 3c 43 4f  44 45 3e 20 26 6c 74 3b  |and .<CODE> &lt;|
000017a0  26 6c 74 3b 20 3c 2f 43  4f 44 45 3e 20 61 73 73  |&lt; </CODE> ass|
000017b0  6f 63 69 61 74 65 73 20  74 6f 20 74 68 65 20 6c  |ociates to the l|
000017c0  65 66 74 2c 20 73 6f 20  74 68 61 74 0a 3c 43 4f  |eft, so that.<CO|
000017d0  44 45 3e 3c 50 52 45 3e  0a 20 20 20 20 20 20 20  |DE><PRE>.       |
000017e0  20 20 20 20 66 70 20 26  6c 74 3b 26 6c 74 3b 20  |    fp &lt;&lt; |
000017f0  73 31 20 26 6c 74 3b 26  6c 74 3b 20 73 32 20 2e  |s1 &lt;&lt; s2 .|
00001800  2e 2e 2e 2e 0a 3c 2f 50  52 45 3e 3c 2f 43 4f 44  |.....</PRE></COD|
00001810  45 3e 0a 69 73 20 65 71  75 69 76 61 6c 65 6e 74  |E>.is equivalent|
00001820  20 74 6f 0a 3c 43 4f 44  45 3e 3c 50 52 45 3e 0a  | to.<CODE><PRE>.|
00001830  20 20 20 20 20 20 20 20  20 20 20 66 70 20 26 6c  |           fp &l|
00001840  74 3b 26 6c 74 3b 20 28  73 31 20 2b 20 73 32 20  |t;&lt; (s1 + s2 |
00001850  2b 20 2e 2e 2e 2e 2e 2e  20 29 0a 3c 2f 50 52 45  |+ ...... ).</PRE|
00001860  3e 3c 2f 43 4f 44 45 3e  0a 0a 3c 48 33 3e 3c 41  |></CODE>..<H3><A|
00001870  20 4e 41 4d 45 3d 22 76  65 63 74 6f 72 22 3e 56  | NAME="vector">V|
00001880  45 43 54 4f 52 3c 2f 41  3e 3c 2f 48 33 3e 0a 56  |ECTOR</A></H3>.V|
00001890  65 63 74 6f 72 73 20 61  72 65 20 61 72 72 61 79  |ectors are array|
000018a0  73 20 6f 66 20 66 69 78  65 64 20 73 69 7a 65 2e  |s of fixed size.|
000018b0  20 54 68 65 69 72 20 63  6f 6d 70 6f 6e 65 6e 74  | Their component|
000018c0  73 20 63 61 6e 20 68 61  76 65 20 61 6e 79 20 74  |s can have any t|
000018d0  79 70 65 2e 0a 49 6e 20  66 61 63 74 20 61 20 76  |ype..In fact a v|
000018e0  65 63 74 6f 72 20 63 61  6e 20 62 65 20 6f 6e 65  |ector can be one|
000018f0  20 6f 66 20 69 74 73 20  6f 77 6e 20 63 6f 6d 70  | of its own comp|
00001900  6f 6e 65 6e 74 73 2e 20  56 65 63 74 6f 72 73 20  |onents. Vectors |
00001910  61 6c 6c 6f 77 20 6f 6e  65 20 0a 74 6f 20 63 6f  |allow one .to co|
00001920  6e 73 74 72 75 63 74 20  63 6f 6d 70 6c 65 78 20  |nstruct complex |
00001930  64 61 74 61 74 79 70 65  73 2e 0a 54 68 65 79 20  |datatypes..They |
00001940  63 61 6e 20 62 65 20 63  72 65 61 74 65 64 20 62  |can be created b|
00001950  79 20 73 74 61 74 65 6d  65 6e 74 73 20 6f 66 20  |y statements of |
00001960  74 68 65 20 66 6f 72 6d  0a 3c 43 4f 44 45 3e 3c  |the form.<CODE><|
00001970  50 52 45 3e 0a 20 20 20  20 20 20 20 20 20 20 20  |PRE>.           |
00001980  76 20 3d 20 6e 65 77 76  65 63 74 6f 72 28 73 69  |v = newvector(si|
00001990  7a 65 29 3b 0a 3c 2f 50  52 45 3e 3c 2f 43 4f 44  |ze);.</PRE></COD|
000019a0  45 3e 0a 77 68 69 63 68  20 63 72 65 61 74 65 73  |E>.which creates|
000019b0  20 61 20 6e 65 77 20 76  65 63 74 6f 72 20 77 69  | a new vector wi|
000019c0  74 68 20 3c 43 4f 44 45  3e 20 73 69 7a 65 20 3c  |th <CODE> size <|
000019d0  2f 43 4f 44 45 3e 20 63  6f 6d 70 6f 6e 65 6e 74  |/CODE> component|
000019e0  73 20 77 68 69 63 68 20  61 72 65 20 0a 61 6c 6c  |s which are .all|
000019f0  20 3c 43 4f 44 45 3e 20  6e 69 6c 20 3c 2f 43 4f  | <CODE> nil </CO|
00001a00  44 45 3e 2e 20 54 68 65  20 63 6f 6d 70 6f 6e 65  |DE>. The compone|
00001a10  6e 74 73 20 61 72 65 0a  3c 43 4f 44 45 3e 3c 50  |nts are.<CODE><P|
00001a20  52 45 3e 0a 20 20 20 20  20 20 20 20 20 20 20 20  |RE>.            |
00001a30  76 5b 30 5d 2c 20 2e 2e  2e 2e 20 2c 20 76 5b 73  |v[0], .... , v[s|
00001a40  69 7a 65 2d 31 5d 0a 3c  2f 50 52 45 3e 3c 2f 43  |ize-1].</PRE></C|
00001a50  4f 44 45 3e 0a 41 6c 74  65 72 6e 61 74 69 76 65  |ODE>.Alternative|
00001a60  6c 79 2c 20 74 68 65 20  65 78 70 72 65 73 73 69  |ly, the expressi|
00001a70  6f 6e 0a 3c 43 4f 44 45  3e 3c 50 52 45 3e 0a 20  |on.<CODE><PRE>. |
00001a80  20 20 20 20 20 20 20 20  20 20 76 65 63 74 6f 72  |          vector|
00001a90  20 7b 20 3c 56 41 52 3e  65 78 70 72 31 3c 2f 56  | { <VAR>expr1</V|
00001aa0  41 52 3e 3b 20 2e 2e 2e  2e 2e 2e 20 3c 56 41 52  |AR>; ...... <VAR|
00001ab0  3e 65 78 70 72 6e 3c 2f  56 41 52 3e 3b 20 7d 0a  |>exprn</VAR>; }.|
00001ac0  3c 2f 50 52 45 3e 3c 2f  43 4f 44 45 3e 0a 72 65  |</PRE></CODE>.re|
00001ad0  74 75 72 6e 73 20 61 20  6e 65 77 20 76 65 63 74  |turns a new vect|
00001ae0  6f 72 20 77 69 74 68 20  63 6f 6d 70 6f 6e 65 6e  |or with componen|
00001af0  74 73 20 3c 56 41 52 3e  65 78 70 72 31 20 2e 2e  |ts <VAR>expr1 ..|
00001b00  2e 20 65 78 70 72 6e 3c  2f 56 41 52 3e 2e 20 0a  |. exprn</VAR>. .|
00001b10  54 68 65 72 65 20 6d 75  73 74 20 62 65 20 61 74  |There must be at|
00001b20  20 6c 65 61 73 74 20 6f  6e 65 20 63 6f 6d 70 6f  | least one compo|
00001b30  6e 65 6e 74 20 61 6e 64  20 6e 6f 74 20 6d 6f 72  |nent and not mor|
00001b40  65 20 74 68 61 6e 20 32  35 35 20 66 6f 72 20 0a  |e than 255 for .|
00001b50  74 68 69 73 20 63 6f 6e  73 74 72 75 63 74 69 6f  |this constructio|
00001b60  6e 2e 20 56 65 63 74 6f  72 73 20 68 61 76 65 20  |n. Vectors have |
00001b70  6f 6e 6c 79 20 6f 6e 65  20 69 6e 64 65 78 2e 20  |only one index. |
00001b80  54 6f 20 64 65 66 69 6e  65 0a 6d 61 74 72 69 63  |To define.matric|
00001b90  65 73 20 77 65 20 63 6f  75 6c 64 20 64 65 66 69  |es we could defi|
00001ba0  6e 65 0a 3c 43 4f 44 45  3e 3c 50 52 45 3e 0a 20  |ne.<CODE><PRE>. |
00001bb0  20 20 6e 65 77 6d 61 74  72 69 78 28 6d 2c 6e 29  |  newmatrix(m,n)|
00001bc0  0a 20 20 20 7b 0a 20 20  20 20 6c 6f 63 61 6c 20  |.   {.    local |
00001bd0  6d 61 74 72 69 78 2c 69  3b 0a 20 20 20 20 6d 61  |matrix,i;.    ma|
00001be0  74 72 69 78 20 3d 20 6e  65 77 76 65 63 74 6f 72  |trix = newvector|
00001bf0  28 6d 29 3b 0a 20 20 20  20 66 6f 72 28 69 3d 30  |(m);.    for(i=0|
00001c00  3b 69 26 6c 74 3b 6d 3b  69 2b 2b 29 0a 20 20 20  |;i&lt;m;i++).   |
00001c10  20 20 20 20 6d 61 74 72  69 78 5b 69 5d 20 3d 20  |    matrix[i] = |
00001c20  6e 65 77 76 65 63 74 6f  72 28 6e 29 3b 0a 20 20  |newvector(n);.  |
00001c30  20 20 72 65 74 75 72 6e  20 6d 61 74 72 69 78 3b  |  return matrix;|
00001c40  0a 20 20 20 7d 0a 3c 2f  50 52 45 3e 3c 2f 43 4f  |.   }.</PRE></CO|
00001c50  44 45 3e 0a 61 6e 64 20  3c 43 4f 44 45 3e 20 6d  |DE>.and <CODE> m|
00001c60  61 74 72 69 78 5b 69 5d  5b 6a 5d 20 3c 2f 43 4f  |atrix[i][j] </CO|
00001c70  44 45 3e 20 77 69 6c 6c  20 62 65 20 74 68 65 20  |DE> will be the |
00001c80  65 6c 65 6d 65 6e 74 20  69 6e 20 74 68 65 20 0a  |element in the .|
00001c90  3c 43 4f 44 45 3e 20 69  20 3c 2f 43 4f 44 45 3e  |<CODE> i </CODE>|
00001ca0  2d 74 68 20 72 6f 77 20  61 6e 64 20 3c 43 4f 44  |-th row and <COD|
00001cb0  45 3e 20 6a 20 3c 2f 43  4f 44 45 3e 2d 74 68 20  |E> j </CODE>-th |
00001cc0  63 6f 6c 75 6d 6e 2e 0a  54 68 69 73 20 68 61 73  |column..This has|
00001cd0  20 74 68 65 20 61 64 76  61 6e 74 61 67 65 20 74  | the advantage t|
00001ce0  68 61 74 20 74 68 65 20  3c 43 4f 44 45 3e 20 69  |hat the <CODE> i|
00001cf0  20 3c 2f 43 4f 44 45 3e  2d 74 68 20 72 6f 77 20  | </CODE>-th row |
00001d00  69 73 20 0a 3c 43 4f 44  45 3e 20 6d 61 74 72 69  |is .<CODE> matri|
00001d10  78 5b 69 5d 20 3c 2f 43  4f 44 45 3e 2e 20 57 68  |x[i] </CODE>. Wh|
00001d20  65 6e 20 61 20 76 65 63  74 6f 72 20 69 73 20 66  |en a vector is f|
00001d30  69 72 73 74 20 63 72 65  61 74 65 64 20 69 74 73  |irst created its|
00001d40  20 0a 63 6f 6d 70 6f 6e  65 6e 74 73 20 61 6c 6c  | .components all|
00001d50  20 68 61 76 65 20 74 68  65 20 76 61 6c 75 65 20  | have the value |
00001d60  3c 43 4f 44 45 3e 20 6e  69 6c 20 3c 2f 43 4f 44  |<CODE> nil </COD|
00001d70  45 3e 2e 20 57 65 20 63  61 6e 20 72 65 70 6c 61  |E>. We can repla|
00001d80  63 65 0a 74 68 65 20 6e  75 6d 65 72 69 63 61 6c  |ce.the numerical|
00001d90  20 69 6e 64 69 63 65 73  20 62 79 20 6e 61 6d 65  | indices by name|
00001da0  73 20 75 73 69 6e 67 20  74 68 65 20 0a 3c 41 20  |s using the .<A |
00001db0  48 52 45 46 3d 22 47 6c  6f 73 73 61 72 79 23 65  |HREF="Glossary#e|
00001dc0  6e 75 6d 3e 20 3c 43 4f  44 45 3e 65 6e 75 6d 20  |num> <CODE>enum |
00001dd0  3c 2f 43 4f 44 45 3e 20  3c 2f 41 3e 0a 66 75 6e  |</CODE> </A>.fun|
00001de0  63 74 69 6f 6e 2e 20 45  2e 67 2e 0a 3c 43 4f 44  |ction. E.g..<COD|
00001df0  45 3e 3c 50 52 45 3e 0a  20 20 20 20 20 20 20 20  |E><PRE>.        |
00001e00  20 20 5f 33 5f 76 65 63  74 6f 72 20 3d 20 65 6e  |  _3_vector = en|
00001e10  75 6d 20 7b 20 78 2c 20  79 2c 20 7a 20 7d 3b 0a  |um { x, y, z };.|
00001e20  20 20 20 20 20 20 20 20  20 20 76 20 20 3d 20 6e  |          v  = n|
00001e30  65 77 76 65 63 74 6f 72  28 5f 33 5f 76 65 63 74  |ewvector(_3_vect|
00001e40  6f 72 29 3b 0a 20 20 20  20 20 20 20 20 20 20 76  |or);.          v|
00001e50  5b 78 5d 20 3d 20 76 5b  79 5d 20 3d 20 76 5b 7a  |[x] = v[y] = v[z|
00001e60  5d 20 3d 20 30 2e 30 3b  0a 3c 2f 50 52 45 3e 3c  |] = 0.0;.</PRE><|
00001e70  2f 43 4f 44 45 3e 0a 0a  3c 48 33 3e 3c 41 20 4e  |/CODE>..<H3><A N|
00001e80  41 4d 45 3d 22 6f 62 6a  65 63 74 22 3e 4f 42 4a  |AME="object">OBJ|
00001e90  45 43 54 3c 2f 41 3e 3c  2f 48 33 3e 0a 46 6f 6c  |ECT</A></H3>.Fol|
00001ea0  6c 6f 77 69 6e 67 20 74  68 65 20 63 6f 6e 76 65  |lowing the conve|
00001eb0  6e 74 69 6f 6e 73 20 6f  66 20 43 2b 2b 2c 20 66  |ntions of C++, f|
00001ec0  6f 72 20 65 76 65 72 79  20 63 6c 61 73 73 20 6f  |or every class o|
00001ed0  6e 65 20 6d 75 73 74 20  64 65 66 69 6e 65 20 61  |ne must define a|
00001ee0  0a 66 75 6e 63 74 69 6f  6e 20 77 69 74 68 20 74  |.function with t|
00001ef0  68 65 20 73 61 6d 65 20  6e 61 6d 65 20 61 73 20  |he same name as |
00001f00  74 68 65 20 63 6c 61 73  73 2c 20 74 6f 20 62 65  |the class, to be|
00001f10  20 75 73 65 64 20 66 6f  72 20 63 72 65 61 74 69  | used for creati|
00001f20  6e 67 0a 69 6e 73 74 61  6e 63 65 20 6f 62 6a 65  |ng.instance obje|
00001f30  63 74 73 20 6f 66 20 74  68 65 20 63 6c 61 73 73  |cts of the class|
00001f40  2e 20 54 68 69 73 20 66  75 6e 63 74 69 6f 6e 20  |. This function |
00001f50  6d 75 73 74 20 65 78 69  74 20 77 69 74 68 20 74  |must exit with t|
00001f60  68 65 0a 73 74 61 74 65  6d 65 6e 74 20 3c 43 4f  |he.statement <CO|
00001f70  44 45 3e 20 72 65 74 75  72 6e 20 74 68 69 73 3b  |DE> return this;|
00001f80  20 3c 2f 43 4f 44 45 3e  2e 20 45 2e 67 2e 0a 3c  | </CODE>. E.g..<|
00001f90  43 4f 44 45 3e 3c 50 52  45 3e 0a 20 20 20 20 20  |CODE><PRE>.     |
00001fa0  20 63 6c 61 73 73 20 70  65 72 73 6f 6e 20 7b 61  | class person {a|
00001fb0  67 65 3b 20 6e 61 6d 65  3b 7d 0a 3c 50 3e 0a 20  |ge; name;}.<P>. |
00001fc0  20 20 20 20 20 70 65 72  73 6f 6e 3a 3a 70 65 72  |     person::per|
00001fd0  73 6f 6e 28 61 2c 6e 29  20 20 20 2f 2f 20 66 6f  |son(a,n)   // fo|
00001fe0  72 20 63 72 65 61 74 69  6e 67 20 6e 65 77 20 70  |r creating new p|
00001ff0  65 72 73 6f 6e 73 0a 20  20 20 20 20 20 7b 20 61  |ersons.      { a|
00002000  67 65 20 3d 20 61 3b 20  6e 61 6d 65 20 3d 20 6e  |ge = a; name = n|
00002010  3b 20 72 65 74 75 72 6e  20 74 68 69 73 3b 7d 0a  |; return this;}.|
00002020  3c 50 3e 0a 20 20 20 20  20 20 70 65 72 73 6f 6e  |<P>.      person|
00002030  3a 3a 68 61 73 5f 61 67  65 28 29 20 20 20 20 20  |::has_age()     |
00002040  2f 2f 20 66 6f 72 20 67  65 74 74 69 6e 67 20 74  |// for getting t|
00002050  68 65 20 61 67 65 20 6f  66 20 61 20 70 65 72 73  |he age of a pers|
00002060  6f 6e 0a 20 20 20 20 20  20 7b 20 72 65 74 75 72  |on.      { retur|
00002070  6e 20 61 67 65 3b 20 7d  0a 3c 50 3e 0a 20 20 20  |n age; }.<P>.   |
00002080  20 20 20 70 65 72 73 6f  6e 3a 3a 63 61 6c 6c 65  |   person::calle|
00002090  64 28 29 20 20 20 20 20  20 2f 2f 20 66 6f 72 20  |d()      // for |
000020a0  67 65 74 74 69 6e 67 20  74 68 65 20 6e 61 6d 65  |getting the name|
000020b0  20 6f 66 20 61 20 70 65  72 73 6f 6e 0a 20 20 20  | of a person.   |
000020c0  20 20 20 7b 20 72 65 74  75 72 6e 20 6e 61 6d 65  |   { return name|
000020d0  3b 20 7d 0a 3c 50 3e 0a  20 20 20 20 20 20 70 65  |; }.<P>.      pe|
000020e0  72 73 6f 6e 3a 3a 6f 6c  64 65 72 28 79 29 20 20  |rson::older(y)  |
000020f0  20 20 20 20 2f 2f 20 66  6f 72 20 6d 61 6b 69 6e  |    // for makin|
00002100  67 20 61 20 70 65 72 73  6f 6e 20 61 67 65 0a 20  |g a person age. |
00002110  20 20 20 20 20 7b 20 61  67 65 20 2b 3d 20 79 3b  |     { age += y;|
00002120  20 7d 0a 3c 50 3e 0a 20  20 20 20 20 20 70 65 72  | }.<P>.      per|
00002130  73 6f 6e 3a 3a 74 65 6c  6c 5f 61 67 65 28 29 20  |son::tell_age() |
00002140  20 20 20 2f 2f 20 74 65  6c 6c 20 68 6f 77 20 6f  |   // tell how o|
00002150  6c 64 20 73 6f 6d 65 6f  6e 65 20 69 73 0a 20 20  |ld someone is.  |
00002160  20 20 20 20 7b 0a 20 20  20 20 20 20 20 73 74 64  |    {.       std|
00002170  6f 75 74 20 26 6c 74 3b  26 6c 74 3b 20 74 68 69  |out &lt;&lt; thi|
00002180  73 2d 3e 63 61 6c 6c 65  64 28 29 0a 20 20 20 20  |s->called().    |
00002190  20 20 20 20 20 20 20 20  20 20 26 6c 74 3b 26 6c  |          &lt;&l|
000021a0  74 3b 20 22 20 69 73 20  22 0a 20 20 20 20 20 20  |t; " is ".      |
000021b0  20 20 20 20 20 20 20 20  26 6c 74 3b 26 6c 74 3b  |        &lt;&lt;|
000021c0  20 74 68 69 73 2d 3e 68  61 73 5f 61 67 65 28 29  | this->has_age()|
000021d0  0a 20 20 20 20 20 20 20  20 20 20 20 20 20 20 26  |.              &|
000021e0  6c 74 3b 26 6c 74 3b 20  22 20 79 65 61 72 73 20  |lt;&lt; " years |
000021f0  6f 6c 64 2e 5c 6e 22 20  3b 0a 20 20 20 20 20 20  |old.\n" ;.      |
00002200  20 7d 0a 3c 50 3e 0a 20  20 20 20 20 20 6d 61 69  | }.<P>.      mai|
00002210  6e 28 29 0a 20 20 20 20  20 20 7b 0a 20 20 20 20  |n().      {.    |
00002220  20 20 20 46 72 65 64 20  3d 20 6e 65 77 20 70 65  |   Fred = new pe|
00002230  72 73 6f 6e 28 33 30 2c  22 46 72 65 64 22 29 3b  |rson(30,"Fred");|
00002240  20 20 2f 2f 20 46 72 65  64 20 69 73 20 62 6f 72  |  // Fred is bor|
00002250  6e 20 33 30 20 79 65 61  72 73 20 6f 6c 64 0a 20  |n 30 years old. |
00002260  20 20 20 20 20 20 46 72  65 64 2d 3e 74 65 6c 6c  |      Fred->tell|
00002270  5f 61 67 65 28 29 3b 0a  20 20 20 20 20 20 20 46  |_age();.       F|
00002280  72 65 64 2d 3e 6f 6c 64  65 72 28 31 30 29 3b 20  |red->older(10); |
00002290  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2f 2f  |              //|
000022a0  20 68 65 20 61 67 65 73  20 31 30 20 79 65 61 72  | he ages 10 year|
000022b0  73 20 20 20 20 20 0a 20  20 20 20 20 20 20 46 72  |s     .       Fr|
000022c0  65 64 2d 3e 74 65 6c 6c  5f 61 67 65 28 29 3b 0a  |ed->tell_age();.|
000022d0  20 20 20 20 20 20 7d 0a  3c 2f 50 52 45 3e 3c 2f  |      }.</PRE></|
000022e0  43 4f 44 45 3e 0a 54 68  69 73 20 65 78 61 6d 70  |CODE>.This examp|
000022f0  6c 65 20 64 65 6d 6f 6e  73 74 72 61 74 65 73 20  |le demonstrates |
00002300  74 68 65 20 75 73 65 20  6f 66 20 74 68 65 20 61  |the use of the a|
00002310  6c 6c 2d 69 6d 70 6f 72  74 61 6e 74 20 6f 70 65  |ll-important ope|
00002320  72 61 74 6f 72 73 0a 3c  41 20 48 52 45 46 3d 22  |rators.<A HREF="|
00002330  47 6c 6f 73 73 61 72 79  23 63 6f 6c 6f 6e 32 22  |Glossary#colon2"|
00002340  3e 20 3c 43 4f 44 45 3e  3a 3a 20 3c 2f 43 4f 44  |> <CODE>:: </COD|
00002350  45 3e 20 3c 2f 41 3e 20  61 6e 64 0a 3c 41 20 48  |E> </A> and.<A H|
00002360  52 45 46 3d 22 47 6c 6f  73 73 61 72 79 23 61 72  |REF="Glossary#ar|
00002370  72 6f 77 22 3e 20 3c 43  4f 44 45 3e 2d 26 67 74  |row"> <CODE>-&gt|
00002380  3b 20 3c 2f 43 4f 44 45  3e 20 3c 2f 41 3e 20 66  |; </CODE> </A> f|
00002390  6f 72 20 64 65 66 69 6e  69 6e 67 0a 61 6e 64 20  |or defining.and |
000023a0  75 73 69 6e 67 20 6d 65  74 68 6f 64 73 2c 20 61  |using methods, a|
000023b0  6e 64 20 74 68 65 20 6b  65 79 77 6f 72 64 20 0a  |nd the keyword .|
000023c0  3c 41 20 48 52 45 46 3d  22 47 6c 6f 73 73 61 72  |<A HREF="Glossar|
000023d0  79 23 6e 65 77 3e 20 3c  43 4f 44 45 3e 6e 65 77  |y#new> <CODE>new|
000023e0  20 3c 2f 43 4f 44 45 3e  20 3c 2f 41 3e 20 66 6f  | </CODE> </A> fo|
000023f0  72 20 63 72 65 61 74 69  6e 67 0a 69 6e 73 74 61  |r creating.insta|
00002400  6e 63 65 20 6f 62 6a 65  63 74 73 2e 0a           |nce objects..|
0000240d