system_overview.rst 8.9 KB

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