3 <!-- Created by texi2html 1.56k from cln.texi on 2 June 2000 -->
5 <TITLE>CLN, a Class Library for Numbers - 8. Symbolic data types</TITLE>
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>.
12 <H1><A NAME="SEC52" HREF="cln_toc.html#TOC52">8. Symbolic data types</A></H1>
18 CLN implements two symbolic (non-numeric) data types: strings and symbols.
23 <H2><A NAME="SEC53" HREF="cln_toc.html#TOC53">8.1 Strings</A></H2>
40 implements immutable strings.
44 Strings are constructed through the following constructors:
49 <DT><CODE>cl_string (const char * s)</CODE>
52 Returns an immutable copy of the (zero-terminated) C string <CODE>s</CODE>.
54 <DT><CODE>cl_string (const char * ptr, unsigned long len)</CODE>
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.
61 The following functions are available on strings:
66 <DT><CODE>operator =</CODE>
68 Assignment from <CODE>cl_string</CODE> and <CODE>const char *</CODE>.
70 <DT><CODE>s.length()</CODE>
73 <DT><CODE>strlen(s)</CODE>
76 Returns the length of the string <CODE>s</CODE>.
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 <= i < s.length()</CODE>.
84 <DT><CODE>bool equal (const cl_string& s1, const cl_string& s2)</CODE>
87 Compares two strings for equality. One of the arguments may also be a
88 plain <CODE>const char *</CODE>.
93 <H2><A NAME="SEC54" HREF="cln_toc.html#TOC54">8.2 Symbols</A></H2>
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.
108 Symbols are constructed through the following constructor:
113 <DT><CODE>cl_symbol (const cl_string& s)</CODE>
115 <A NAME="IDX278"></A>
116 Looks up or creates a new symbol with a given name.
120 The following operations are available on symbols:
125 <DT><CODE>cl_string (const cl_symbol& sym)</CODE>
127 Conversion to <CODE>cl_string</CODE>: Returns the string which names the symbol
130 <DT><CODE>bool equal (const cl_symbol& sym1, const cl_symbol& sym2)</CODE>
132 <A NAME="IDX279"></A>
133 Compares two symbols for equality. This is very fast.
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>.