builtin_fn_pred.d.elv 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #elvdoc:fn bool
  2. #
  3. # ```elvish
  4. # bool $value
  5. # ```
  6. #
  7. # Convert a value to boolean. In Elvish, only `$false` and errors are booleanly
  8. # false. Everything else, including 0, empty strings and empty lists, is booleanly
  9. # true:
  10. #
  11. # ```elvish-transcript
  12. # ~> bool $true
  13. # ▶ $true
  14. # ~> bool $false
  15. # ▶ $false
  16. # ~> bool $ok
  17. # ▶ $true
  18. # ~> bool ?(fail haha)
  19. # ▶ $false
  20. # ~> bool ''
  21. # ▶ $true
  22. # ~> bool []
  23. # ▶ $true
  24. # ~> bool abc
  25. # ▶ $true
  26. # ```
  27. #
  28. # @cf not
  29. #elvdoc:fn not
  30. #
  31. # ```elvish
  32. # not $value
  33. # ```
  34. #
  35. # Boolean negation. Examples:
  36. #
  37. # ```elvish-transcript
  38. # ~> not $true
  39. # ▶ $false
  40. # ~> not $false
  41. # ▶ $true
  42. # ~> not $ok
  43. # ▶ $false
  44. # ~> not ?(fail error)
  45. # ▶ $true
  46. # ```
  47. #
  48. # **Note**: The related logical commands `and` and `or` are implemented as
  49. # [special commands](language.html#special-commands) instead, since they do not
  50. # always evaluate all their arguments. The `not` command always evaluates its
  51. # only argument, and is thus a normal command.
  52. #
  53. # @cf bool
  54. #elvdoc:fn is
  55. #
  56. # ```elvish
  57. # is $values...
  58. # ```
  59. #
  60. # Determine whether all `$value`s have the same identity. Writes `$true` when
  61. # given no or one argument.
  62. #
  63. # The definition of identity is subject to change. Do not rely on its behavior.
  64. #
  65. # ```elvish-transcript
  66. # ~> is a a
  67. # ▶ $true
  68. # ~> is a b
  69. # ▶ $false
  70. # ~> is [] []
  71. # ▶ $true
  72. # ~> is [a] [a]
  73. # ▶ $false
  74. # ```
  75. #
  76. # @cf eq
  77. #
  78. # Etymology: [Python](https://docs.python.org/3/reference/expressions.html#is).
  79. #elvdoc:fn eq
  80. #
  81. # ```elvish
  82. # eq $values...
  83. # ```
  84. #
  85. # Determines whether all `$value`s are equal. Writes `$true` when
  86. # given no or one argument.
  87. #
  88. # Two values are equal when they have the same type and value.
  89. #
  90. # For complex data structures like lists and maps, comparison is done
  91. # recursively. A pseudo-map is equal to another pseudo-map with the same
  92. # internal type (which is not exposed to Elvish code now) and value.
  93. #
  94. # ```elvish-transcript
  95. # ~> eq a a
  96. # ▶ $true
  97. # ~> eq [a] [a]
  98. # ▶ $true
  99. # ~> eq [&k=v] [&k=v]
  100. # ▶ $true
  101. # ~> eq a [b]
  102. # ▶ $false
  103. # ```
  104. #
  105. # @cf is not-eq
  106. #
  107. # Etymology: [Perl](https://perldoc.perl.org/perlop.html#Equality-Operators).
  108. #elvdoc:fn not-eq
  109. #
  110. # ```elvish
  111. # not-eq $values...
  112. # ```
  113. #
  114. # Determines whether every adjacent pair of `$value`s are not equal. Note that
  115. # this does not imply that `$value`s are all distinct. Examples:
  116. #
  117. # ```elvish-transcript
  118. # ~> not-eq 1 2 3
  119. # ▶ $true
  120. # ~> not-eq 1 2 1
  121. # ▶ $true
  122. # ~> not-eq 1 1 2
  123. # ▶ $false
  124. # ```
  125. #
  126. # @cf eq
  127. #elvdoc:fn compare
  128. #
  129. # ```elvish
  130. # compare $a $b
  131. # ```
  132. #
  133. # Outputs -1 if `$a` < `$b`, 0 if `$a` = `$b`, and 1 if `$a` > `$b`.
  134. #
  135. # The following comparison algorithm is used:
  136. #
  137. # - Typed numbers are compared numerically. The comparison is consistent with
  138. # the [number comparison commands](#num-cmp), except that `NaN` values are
  139. # considered equal to each other and smaller than all other numbers.
  140. #
  141. # - Strings are compared lexicographically by bytes, consistent with the
  142. # [string comparison commands](#str-cmp). For UTF-8 encoded strings, this is
  143. # equivalent to comparing by codepoints.
  144. #
  145. # - Lists are compared lexicographically by elements, if the elements at the
  146. # same positions are comparable.
  147. #
  148. # If the ordering between two elements is not defined by the conditions above,
  149. # i.e. if the value of `$a` or `$b` is not covered by any of the cases above or
  150. # if they belong to different cases, a "bad value" exception is thrown.
  151. #
  152. # Examples:
  153. #
  154. # ```elvish-transcript
  155. # ~> compare a b
  156. # ▶ (num 1)
  157. # ~> compare b a
  158. # ▶ (num -1)
  159. # ~> compare x x
  160. # ▶ (num 0)
  161. # ~> compare (num 10) (num 1)
  162. # ▶ (num 1)
  163. # ```
  164. #
  165. # Beware that strings that look like numbers are treated as strings, not
  166. # numbers.
  167. #
  168. # @cf order