system_overview.rst 8.6 KB

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