system_overview.rst 8.4 KB

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