You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.2 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. <HTML>
  2. <HEAD>
  3. <!-- Created by texi2html 1.56k from cln.texi on 4 May 2000 -->
  4. <TITLE>CLN, a Class Library for Numbers - 8. Symbolic data types</TITLE>
  5. </HEAD>
  6. <BODY>
  7. 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>.
  8. <P><HR><P>
  9. <H1><A NAME="SEC51" HREF="cln_toc.html#TOC51">8. Symbolic data types</A></H1>
  10. <P>
  11. <A NAME="IDX259"></A>
  12. <P>
  13. CLN implements two symbolic (non-numeric) data types: strings and symbols.
  14. <H2><A NAME="SEC52" HREF="cln_toc.html#TOC52">8.1 Strings</A></H2>
  15. <P>
  16. <A NAME="IDX260"></A>
  17. <P>
  18. The class
  19. <PRE>
  20. String
  21. cl_string
  22. &#60;cl_string.h&#62;
  23. </PRE>
  24. <P>
  25. implements immutable strings.
  26. <P>
  27. Strings are constructed through the following constructors:
  28. <DL COMPACT>
  29. <DT><CODE>cl_string (const char * s)</CODE>
  30. <DD>
  31. <A NAME="IDX261"></A>
  32. Returns an immutable copy of the (zero-terminated) C string <CODE>s</CODE>.
  33. <DT><CODE>cl_string (const char * ptr, unsigned long len)</CODE>
  34. <DD>
  35. Returns an immutable copy of the <CODE>len</CODE> characters at
  36. <CODE>ptr[0]</CODE>, ..., <CODE>ptr[len-1]</CODE>. NUL characters are allowed.
  37. </DL>
  38. <P>
  39. The following functions are available on strings:
  40. <DL COMPACT>
  41. <DT><CODE>operator =</CODE>
  42. <DD>
  43. Assignment from <CODE>cl_string</CODE> and <CODE>const char *</CODE>.
  44. <DT><CODE>s.length()</CODE>
  45. <DD>
  46. <A NAME="IDX262"></A>
  47. <DT><CODE>strlen(s)</CODE>
  48. <DD>
  49. <A NAME="IDX263"></A>
  50. Returns the length of the string <CODE>s</CODE>.
  51. <DT><CODE>s[i]</CODE>
  52. <DD>
  53. <A NAME="IDX264"></A>
  54. Returns the <CODE>i</CODE>th character of the string <CODE>s</CODE>.
  55. <CODE>i</CODE> must be in the range <CODE>0 &#60;= i &#60; s.length()</CODE>.
  56. <DT><CODE>bool equal (const cl_string&#38; s1, const cl_string&#38; s2)</CODE>
  57. <DD>
  58. <A NAME="IDX265"></A>
  59. Compares two strings for equality. One of the arguments may also be a
  60. plain <CODE>const char *</CODE>.
  61. </DL>
  62. <H2><A NAME="SEC53" HREF="cln_toc.html#TOC53">8.2 Symbols</A></H2>
  63. <P>
  64. <A NAME="IDX266"></A>
  65. <P>
  66. Symbols are uniquified strings: all symbols with the same name are shared.
  67. This means that comparison of two symbols is fast (effectively just a pointer
  68. comparison), whereas comparison of two strings must in the worst case walk
  69. both strings until their end.
  70. Symbols are used, for example, as tags for properties, as names of variables
  71. in polynomial rings, etc.
  72. <P>
  73. Symbols are constructed through the following constructor:
  74. <DL COMPACT>
  75. <DT><CODE>cl_symbol (const cl_string&#38; s)</CODE>
  76. <DD>
  77. <A NAME="IDX267"></A>
  78. Looks up or creates a new symbol with a given name.
  79. </DL>
  80. <P>
  81. The following operations are available on symbols:
  82. <DL COMPACT>
  83. <DT><CODE>cl_string (const cl_symbol&#38; sym)</CODE>
  84. <DD>
  85. Conversion to <CODE>cl_string</CODE>: Returns the string which names the symbol
  86. <CODE>sym</CODE>.
  87. <DT><CODE>bool equal (const cl_symbol&#38; sym1, const cl_symbol&#38; sym2)</CODE>
  88. <DD>
  89. <A NAME="IDX268"></A>
  90. Compares two symbols for equality. This is very fast.
  91. </DL>
  92. <P><HR><P>
  93. 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>.
  94. </BODY>
  95. </HTML>