system_overview.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. .. default-role:: code
  2. .. include:: ../doc/rstcommon.rst
  3. The System module imports several separate modules, and their documentation
  4. is in separate files:
  5. * `iterators <iterators.html>`_
  6. * `exceptions <exceptions.html>`_
  7. * `assertions <assertions.html>`_
  8. * `dollars <dollars.html>`_
  9. * `ctypes <ctypes.html>`_
  10. * `repr_v2 <repr_v2.html>`_
  11. Here is a short overview of the most commonly used functions from the
  12. `system` module. Function names in the tables below are clickable and
  13. will take you to the full documentation of the function.
  14. There are many more functions available than the ones listed in this overview.
  15. Use the table of contents on the left-hand side and/or `Ctrl+F` to navigate
  16. through this module.
  17. Strings and characters
  18. ----------------------
  19. ============================= =======================================
  20. Proc Usage
  21. ============================= =======================================
  22. `len(s)<#len,string>`_ Return the length of a string
  23. `chr(i)<#chr,range[]>`_ Convert an `int` in the range `0..255`
  24. to a character
  25. `ord(c)<#ord,T>`_ Return `int` value of a character
  26. `a & b<#&,string,string>`_ Concatenate two strings
  27. `s.add(c)<#add,string,char>`_ Add character to the string
  28. `$<dollars.html>`_ Convert various types to string
  29. ============================= =======================================
  30. **See also:**
  31. * `strutils module <strutils.html>`_ for common string functions
  32. * `strformat module <strformat.html>`_ for string interpolation and formatting
  33. * `unicode module <unicode.html>`_ for Unicode UTF-8 handling
  34. * `strscans <strscans.html>`_ for `scanf` and `scanp` macros, which offer
  35. easier substring extraction than regular expressions
  36. * `strtabs module <strtabs.html>`_ for efficient hash tables
  37. (dictionaries, in some programming languages) mapping from strings to strings
  38. Seqs
  39. ----
  40. ============================================================= ==========================================
  41. Proc Usage
  42. ============================================================= ==========================================
  43. `newSeq<#newSeq>`_ Create a new sequence of a given length
  44. `newSeqOfCap<#newSeqOfCap,Natural>`_ Create a new sequence with zero length
  45. and a given capacity
  46. `setLen<#setLen,seq[T],Natural>`_ Set the length of a sequence
  47. `len<#len,seq[T]>`_ Return the length of a sequence
  48. `@<#@,openArray[T]>`_ Turn an array into a sequence
  49. `add<#add,seq[T],sinkT>`_ Add an item to the sequence
  50. `insert<#insert,seq[T],sinkT>`_ Insert an item at a specific position
  51. `delete<#delete,seq[T],Natural>`_ Delete an item while preserving the
  52. order of elements (`O(n)` operation)
  53. `del<#del,seq[T],Natural>`_ `O(1)` removal, doesn't preserve the order
  54. `pop<#pop,seq[T]>`_ Remove and return last item of a sequence
  55. `x & y<#&,seq[T],seq[T]>`_ Concatenate two sequences
  56. `x[a .. b]<#[],openArray[T],HSlice[U: Ordinal,V: Ordinal]>`_ Slice of a sequence (both ends included)
  57. `x[a .. ^b]<#[],openArray[T],HSlice[U: Ordinal,V: Ordinal]>`_ Slice of a sequence but `b` is a
  58. reversed index (both ends included)
  59. `x[a ..< b]<#[],openArray[T],HSlice[U: Ordinal,V: Ordinal]>`_ Slice of a sequence (excluded upper bound)
  60. ============================================================= ==========================================
  61. **See also:**
  62. * `sequtils module <sequtils.html>`_ for operations on container
  63. types (including strings)
  64. * `json module <json.html>`_ for a structure which allows heterogeneous members
  65. * `lists module <lists.html>`_ for linked lists
  66. Sets
  67. ----
  68. Built-in bit sets.
  69. =============================== ======================================
  70. Proc Usage
  71. =============================== ======================================
  72. `incl<#incl,set[T],T>`_ Include element `y` in the set `x`
  73. `excl<#excl,set[T],T>`_ Exclude element `y` from the set `x`
  74. `card<#card,set[T]>`_ Return the cardinality of the set,
  75. i.e. the number of elements
  76. `a * b<#*,set[T],set[T]>`_ Intersection
  77. `a + b<#+,set[T],set[T]>`_ Union
  78. `a - b<#-,set[T],set[T]>`_ Difference
  79. `contains<#contains,set[T],T>`_ Check if an element is in the set
  80. [a < b](#<,set[T],set[T]) Check if `a` is a subset of `b`
  81. =============================== ======================================
  82. **See also:**
  83. * `setutils module <setutils.html>`_ for bit set convenience functions
  84. * `sets module <sets.html>`_ for hash sets
  85. * `intsets module <intsets.html>`_ for efficient int sets
  86. Numbers
  87. -------
  88. ============================== ================================== =====================
  89. Proc Usage Also known as
  90. (in other languages)
  91. ============================== ================================== =====================
  92. `div<#div,int,int>`_ Integer division `//`
  93. `mod<#mod,int,int>`_ Integer modulo (remainder) `%`
  94. `shl<#shl,int,SomeInteger>`_ Shift left `<<`
  95. `shr<#shr,int,SomeInteger>`_ Shift right `>>`
  96. `ashr<#ashr,int,SomeInteger>`_ Arithmetic shift right
  97. `and<#and,int,int>`_ Bitwise `and` `&`
  98. `or<#or,int,int>`_ Bitwise `or` `|`
  99. `xor<#xor,int,int>`_ Bitwise `xor` `^`
  100. `not<#not,int>`_ Bitwise `not` (complement) `~`
  101. `toInt<#toInt,float>`_ Convert floating-point number
  102. into an `int`
  103. `toFloat<#toFloat,int>`_ Convert an integer into a `float`
  104. ============================== ================================== =====================
  105. **See also:**
  106. * `math module <math.html>`_ for mathematical operations like trigonometric
  107. functions, logarithms, square and cubic roots, etc.
  108. * `complex module <complex.html>`_ for operations on complex numbers
  109. * `rationals module <rationals.html>`_ for rational numbers
  110. Ordinals
  111. --------
  112. `Ordinal type <#Ordinal>`_ includes integer, bool, character, and enumeration
  113. types, as well as their subtypes.
  114. ===================== =======================================
  115. Proc Usage
  116. ===================== =======================================
  117. succ_ Successor of the value
  118. pred_ Predecessor of the value
  119. inc_ Increment the ordinal
  120. dec_ Decrement the ordinal
  121. `high<#high,T>`_ Return the highest possible value
  122. `low<#low,T>`_ Return the lowest possible value
  123. `ord<#ord,T>`_ Return `int` value of an ordinal value
  124. ===================== =======================================
  125. Misc
  126. ----
  127. ==================================================== ============================================
  128. Proc Usage
  129. ==================================================== ============================================
  130. `is<#is,T,S>`_ Check if two arguments are of the same type
  131. `isnot<#isnot.t,untyped,untyped>`_ Negated version of `is`
  132. `!=<#!%3D.t,untyped,untyped>`_ Not equals
  133. `addr<#addr,T>`_ Take the address of a memory location
  134. `T and F<#and,bool,bool>`_ Boolean `and`
  135. `T or F<#or,bool,bool>`_ Boolean `or`
  136. `T xor F<#xor,bool,bool>`_ Boolean `xor` (exclusive or)
  137. `not T<#not,bool>`_ Boolean `not`
  138. `a[^x]<#^.t,int>`_ Take the element at the reversed index `x`
  139. `a .. b<#..,sinkT,sinkU>`_ Binary slice that constructs an interval
  140. `[a, b]`
  141. `a ..^ b<#..^.t,untyped,untyped>`_ Interval `[a, b]` but `b` as reversed index
  142. [a ..< b](#..<.t,untyped,untyped) Interval `[a, b)` (excluded upper bound)
  143. [runnableExamples](#runnableExamples,string,untyped) Create testable documentation
  144. ==================================================== ============================================