# system/dollars

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

`$` is Nim's general way of spelling toString.

Example:

    import system/dollars
    assert $0.1 == "0.1"
    assert $(-2*3) == "-6"

# Imports

digitsutils, miscdollars, formatfloat, objectdollar

# Procs

    proc `$`(t: typedesc): string {.magic: "TypeTrait", ...raises: [], tags: [],
                                    forbids: [].}

  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 `$`(x: bool): string {.magic: "BoolToStr", noSideEffect, ...raises: [],
                                tags: [], forbids: [].}

  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, ...raises: [],
                                tags: [], forbids: [].}

  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, ...raises: [],
                                   tags: [], forbids: [].}

  The stringify operator for a CString argument. Returns `x` converted to a string. Source Edit

    func `$`(x: float | float32): string

  Outplace version of `addFloat`. Source Edit

    proc `$`(x: string): string {.magic: "StrToStr", noSideEffect, ...raises: [],
                                  tags: [], forbids: [].}

  The stringify operator for a string argument. Returns `x` as it is. This operator is useful for generic code, so that `$expr` also works if `expr` is already a string. Source Edit

    proc `$`(x`gensym0: int): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym1: int8): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym2: int16): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym3: int32): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym4: int64): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym5: uint): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym6: uint8): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym7: uint16): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym8: uint32): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    proc `$`(x`gensym9: uint64): string {....raises: [], tags: [], forbids: [].}

  Outplace version of `addInt`. Source Edit

    func `$`(x`gensym10: `{}`(int, lit)): string {.compileTime, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    func `$`(x`gensym11: `{}`(uint64, lit)): string {.compileTime, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    func `$`(x`gensym12: `{}`(int64, lit)): string {.compileTime, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc `$`[Enum: enum](x: Enum): string {.magic: "EnumToStr", noSideEffect,
                                            ...raises: [], tags: [], forbids: [].}

  The stringify operator for an enumeration argument. This works for any enumeration type thanks to compiler magic.

  If a `$` operator for a concrete enumeration is provided, this is used instead. (In other words: Overwriting is possible.)

  Source Edit

    proc `$`[T, IDX](x: array[IDX, T]): string

  Generic `$` operator for arrays that is lifted from the components. Source Edit

    proc `$`[T, U](x: HSlice[T, U]): string

  Generic `$` operator for slices that is lifted from the components of `x`. Example:

      $(1 .. 5) == "1 .. 5"

  Source Edit

    proc `$`[T: tuple](x: T): string

  Generic `$` operator for tuples that is lifted from the components of `x`. Example:

      $(23, 45) == "(23, 45)"
      $(a: 23, b: 45) == "(a: 23, b: 45)"
      $() == "()"

  Source Edit

    proc `$`[T](x: openArray[T]): string

  Generic `$` operator for openarrays that is lifted from the components of `x`. Example:

      $(@[23, 45].toOpenArray(0, 1)) == "[23, 45]"

  Source Edit

    proc `$`[T](x: seq[T]): string

  Generic `$` operator for seqs that is lifted from the components of `x`. Example:

      $(@[23, 45]) == "@[23, 45]"

  Source Edit

    proc `$`[T](x: set[T]): string

  Generic `$` operator for sets that is lifted from the components of `x`. Example:

      ${23, 45} == "{23, 45}"

  Source Edit

# Exports

addFloat, $