[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 8. Symbolic data types

CLN implements two symbolic (non-numeric) data types: strings and symbols.

> 8.1 Strings |  |
> 8.2 Symbols |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 8.1 Strings

The class

                          String
                         cl_string
                       <cln/string.h>

implements immutable strings.

Strings are constructed through the following constructors:

`cl_string (const char * s)`
  Returns an immutable copy of the (zero-terminated) C string `s`.

`cl_string (const char * ptr, unsigned long len)`
  Returns an immutable copy of the `len` characters at `ptr[0]`, ..., `ptr[len-1]`. NUL characters are allowed.

The following functions are available on strings:

`operator =`
  Assignment from `cl_string` and `const char *`.

`s.length()`
`strlen(s)`
  Returns the length of the string `s`.

`s[i]`
  Returns the `i`th character of the string `s`. `i` must be in the range `0 <= i < s.length()`.

`bool equal (const cl_string& s1, const cl_string& s2)`
  Compares two strings for equality. One of the arguments may also be a plain `const char *`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 8.2 Symbols

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.

Symbols are constructed through the following constructor:

`cl_symbol (const cl_string& s)`
  Looks up or creates a new symbol with a given name.

The following operations are available on symbols:

`cl_string (const cl_symbol& sym)`
  Conversion to `cl_string`: Returns the string which names the symbol `sym`.

`bool equal (const cl_symbol& sym1, const cl_symbol& sym2)`
  Compares two symbols for equality. This is very fast.

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Richard B. Kreckel on May, 28 2002 using texi2html