dollars
Imports
Procs
proc `$`(x: int): string {...}{.magic: "IntToStr", noSideEffect.}
- The stringify operator for an integer argument. Returns
x
converted to a decimal string.$
is Nim's general way of spelling toString. Source Edit proc `$`(x: uint64): string {...}{.noSideEffect, raises: [], tags: [].}
- The stringify operator for an unsigned integer argument. Returns
x
converted to a decimal string. Source Edit proc `$`(x: int64): string {...}{.magic: "Int64ToStr", noSideEffect.}
- The stringify operator for an integer argument. Returns
x
converted to a decimal string. Source Edit proc `$`(x: float): string {...}{.magic: "FloatToStr", noSideEffect.}
- The stringify operator for a float argument. Returns
x
converted to a decimal string. Source Edit proc `$`(x: bool): string {...}{.magic: "BoolToStr", noSideEffect.}
- The stringify operator for a boolean argument. Returns
x
converted to the string "false" or "true". Source Edit proc `$`(x: char): string {...}{.magic: "CharToStr", noSideEffect.}
- The stringify operator for a character argument. Returns
x
converted to a string.assert $'c' == "c"
Source Edit proc `$`(x: cstring): string {...}{.magic: "CStrToStr", noSideEffect.}
- The stringify operator for a CString argument. Returns
x
converted to a string. Source Edit proc `$`(x: string): string {...}{.magic: "StrToStr", noSideEffect.}
- The stringify operator for a string argument. Returns
x
as it is. This operator is useful for generic code, so that$expr
also works ifexpr
is already a string. Source Edit proc `$`[Enum: enum](x: Enum): string {...}{.magic: "EnumToStr", noSideEffect.}
-
The stringify operator for an enumeration argument. This works for any enumeration type thanks to compiler magic.
If a
Source Edit$
operator for a concrete enumeration is provided, this is used instead. (In other words: Overwriting is possible.) proc `$`(t: typedesc): string {...}{.magic: "TypeTrait".}
-
Returns the name of the given type.
For more procedures dealing with
typedesc
, see typetraits module.doAssert $(typeof(42)) == "int" doAssert $(typeof("Foo")) == "string" static: doAssert $(typeof(@['A', 'B'])) == "seq[char]"
Source Edit proc `$`[T: tuple | object](x: T): string
- Generic
$
operator for tuples that is lifted from the components ofx
. Example:$(23, 45) == "(23, 45)" $(a: 23, b: 45) == "(a: 23, b: 45)" $() == "()"
Source Edit proc `$`[T](x: set[T]): string
- Generic
$
operator for sets that is lifted from the components ofx
. Example:${23, 45} == "{23, 45}"
Source Edit proc `$`[T](x: seq[T]): string
- Generic
$
operator for seqs that is lifted from the components ofx
. Example:$(@[23, 45]) == "@[23, 45]"
Source Edit proc `$`[T, U](x: HSlice[T, U]): string
- Generic
$
operator for slices that is lifted from the components ofx
. Example:$(1 .. 5) == "1 .. 5"
Source Edit proc `$`[T, IDX](x: array[IDX, T]): string
- Generic
$
operator for arrays that is lifted from the components. Source Edit proc `$`[T](x: openArray[T]): string
- Generic
$
operator for openarrays that is lifted from the components ofx
. Example:$(@[23, 45].toOpenArray(0, 1)) == "[23, 45]"
Source Edit
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/dollars.html