1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
from cln.texi on 2 Febuary 1998 -->
<TITLE>CLN, a Class Library for Numbers - 8 Symbolic data types</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_7.html">previous</A>, <A HREF="cln_9.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
<P><HR><P>
<H1><A NAME="SEC49" HREF="cln_toc.html#TOC49">8 Symbolic data types</A></H1>
<P>
CLN implements two symbolic (non-numeric) data types: strings and symbols.
</P>
<H2><A NAME="SEC50" HREF="cln_toc.html#TOC50">8.1 Strings</A></H2>
<P>
The class
</P>
<PRE>
String
cl_string
<cl_string.h>
</PRE>
<P>
implements immutable strings.
</P>
<P>
Strings are constructed through the following constructors:
</P>
<DL COMPACT>
<DT><CODE>cl_string (const char * s)</CODE>
<DD>
Returns an immutable copy of the (zero-terminated) C string <CODE>s</CODE>.
<DT><CODE>cl_string (const char * ptr, unsigned long len)</CODE>
<DD>
Returns an immutable copy of the <CODE>len</CODE> characters at
<CODE>ptr[0]</CODE>, ..., <CODE>ptr[len-1]</CODE>. NUL characters are allowed.
</DL>
<P>
The following functions are available on strings:
</P>
<DL COMPACT>
<DT><CODE>operator =</CODE>
<DD>
Assignment from <CODE>cl_string</CODE> and <CODE>const char *</CODE>.
<DT><CODE>s.length()</CODE>
<DD>
<DT><CODE>strlen(s)</CODE>
<DD>
Returns the length of the string <CODE>s</CODE>.
<DT><CODE>s[i]</CODE>
<DD>
Returns the <CODE>i</CODE>th character of the string <CODE>s</CODE>.
<CODE>i</CODE> must be in the range <CODE>0 <= i < s.length()</CODE>.
<DT><CODE>bool equal (const cl_string& s1, const cl_string& s2)</CODE>
<DD>
Compares two strings for equality. One of the arguments may also be a
plain <CODE>const char *</CODE>.
</DL>
<H2><A NAME="SEC51" HREF="cln_toc.html#TOC51">8.2 Symbols</A></H2>
<P>
Symbols are uniquified strings: all symbols with the same name are shared.
This means that comparison of two symbols is fast (effectively just a pointer
comparison), whereas comparison of two strings must in the worst case walk
both strings until their end.
Symbols are used, for example, as tags for properties, as names of variables
in polynomial rings, etc.
</P>
<P>
Symbols are constructed through the following constructor:
</P>
<DL COMPACT>
<DT><CODE>cl_symbol (const cl_string& s)</CODE>
<DD>
Looks up or creates a new symbol with a given name.
</DL>
<P>
The following operations are available on symbols:
</P>
<DL COMPACT>
<DT><CODE>cl_string (const cl_symbol& sym)</CODE>
<DD>
Conversion to <CODE>cl_string</CODE>: Returns the string which names the symbol
<CODE>sym</CODE>.
<DT><CODE>bool equal (const cl_symbol& sym1, const cl_symbol& sym2)</CODE>
<DD>
Compares two symbols for equality. This is very fast.
</DL>
<P><HR><P>
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_7.html">previous</A>, <A HREF="cln_9.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
</BODY>
</HTML>
|