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