system_overview.rst 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * `sets module <sets.html>`_ for hash sets
  83. * `intsets module <intsets.html>`_ for efficient int sets
  84. Numbers
  85. -------
  86. ============================== ================================== =====================
  87. Proc Usage Also known as
  88. (in other languages)
  89. ============================== ================================== =====================
  90. `div<#div,int,int>`_ Integer division `//`
  91. `mod<#mod,int,int>`_ Integer modulo (remainder) `%`
  92. `shl<#shl,int,SomeInteger>`_ Shift left `<<`
  93. `shr<#shr,int,SomeInteger>`_ Shift right `>>`
  94. `ashr<#ashr,int,SomeInteger>`_ Arithmetic shift right
  95. `and<#and,int,int>`_ Bitwise `and` `&`
  96. `or<#or,int,int>`_ Bitwise `or` `|`
  97. `xor<#xor,int,int>`_ Bitwise `xor` `^`
  98. `not<#not,int>`_ Bitwise `not` (complement) `~`
  99. `toInt<#toInt,float>`_ Convert floating-point number
  100. into an `int`
  101. `toFloat<#toFloat,int>`_ Convert an integer into a `float`
  102. ============================== ================================== =====================
  103. **See also:**
  104. * `math module <math.html>`_ for mathematical operations like trigonometric
  105. functions, logarithms, square and cubic roots, etc.
  106. * `complex module <complex.html>`_ for operations on complex numbers
  107. * `rationals module <rationals.html>`_ for rational numbers
  108. Ordinals
  109. --------
  110. `Ordinal type <#Ordinal>`_ includes integer, bool, character, and enumeration
  111. types, as well as their subtypes.
  112. ===================== =======================================
  113. Proc Usage
  114. ===================== =======================================
  115. `succ<#succ,T,int>`_ Successor of the value
  116. `pred<#pred,T,int>`_ Predecessor of the value
  117. `inc<#inc,T,int>`_ Increment the ordinal
  118. `dec<#dec,T,int>`_ Decrement the ordinal
  119. `high<#high,T>`_ Return the highest possible value
  120. `low<#low,T>`_ Return the lowest possible value
  121. `ord<#ord,T>`_ Return `int` value of an ordinal value
  122. ===================== =======================================
  123. Misc
  124. ----
  125. ==================================================== ============================================
  126. Proc Usage
  127. ==================================================== ============================================
  128. `is<#is,T,S>`_ Check if two arguments are of the same type
  129. `isnot<#isnot.t,untyped,untyped>`_ Negated version of `is`
  130. `!=<#!%3D.t,untyped,untyped>`_ Not equals
  131. `addr<#addr,T>`_ Take the address of a memory location
  132. `T and F<#and,bool,bool>`_ Boolean `and`
  133. `T or F<#or,bool,bool>`_ Boolean `or`
  134. `T xor F<#xor,bool,bool>`_ Boolean `xor` (exclusive or)
  135. `not T<#not,bool>`_ Boolean `not`
  136. `a[^x]<#^.t,int>`_ Take the element at the reversed index `x`
  137. `a .. b<#..,sinkT,sinkU>`_ Binary slice that constructs an interval
  138. `[a, b]`
  139. `a ..^ b<#..^.t,untyped,untyped>`_ Interval `[a, b]` but `b` as reversed index
  140. [a ..< b](#..<.t,untyped,untyped) Interval `[a, b)` (excluded upper bound)
  141. [runnableExamples](#runnableExamples,string,untyped) Create testable documentation
  142. ==================================================== ============================================