simple types
TLDR
- Conversion between int and int32 or int64 must be explicit except for string literals.
- stay away from blah% operators in practice
- % are mainly for backwards compatibility with previous nim versions
- generally procs that work for strings work for chars
- generally strings can use any seq proc for manipulation
- similar to js isNull, use blah.isNil, or blah != nil
- however you cannot if blah not nil: ...
links
string
- value semantics
- are really just seqchar|byte except for the terminating nullbyte 0
- ^0 terminated so nim strings can be converted to a cstring without a copy
- compared using lexicographical order
- to intrepret unicode, you need to import the unicode module
- addQuoted escapes and quotes y then appends to x in place
- addEscapedChar escapes y (backslashes everything) then appends to x
char
- 8 bit char (unsigned, basically an alias for uint8)
- always 1 byte so cant represent most UTF-8 chars
- single ASCII characters
- enclosed in single quotes
byte
- alias for uint8 that is 8 bits wide
- if dealing with binary blobs, prefer seqbyte > string,
- if dealing with binary data, prefer seqchar|uint8
- ByteAddress alias for int, used for converting pointers to itneger addresses
bool
- only true & false (i.e. not 1/0) evaluate to bool
- but its an enum, so 0=false, 1=true
- off/on are aliases for true/false
- if and while conditions must be of type bool
boolean procs
- != == etc
- is
- isnot
- not
- notin
- and
- or
- in
- xor
- of
comparisons
- cmp two numbers/strings
string/char procs
- len(s) Return the length of a string
- chr(i) Convert an int in the range 0..255 to a character
- ord(c) Return int value of a character
- a & b Concatenate two strings
- s.add(c) Add character to the string
- $ Convert various types to string
- substr
- find returns index of char in string
- contains true/false
numbers
number procs
- and Bitwise and &
- ashr Arithmetic shift right
- abs value of some number
- div Integer division
- high(NumberType)
- Inf == high(int)
- low(NumberType)
- max(x,y)
- min(x,y)
- mod Integer modulo (remainder) %
- not Bitwise not (complement) ~
- or Bitwise or |
- Positive range1..high(int)
- shl Shift left <<
- shr Shift right >>
- toBiggestFloat
- toBiggestInt
- toFloat Convert an integer into a float
- toInt Convert floating-point number into an int
- xor Bitwise xor ^
number types
- BackwardsIndex alias for distinct int, see range docs
- BiggestInt alias for int64
- BiggestUInt alias uinty64
- float (alias for float64|BiggestFloat) === processors fastest type,
- float32,64
- Inf float64 infinity
- int (signed), 32bit/64bit os arch, platform word size, bitwidth depends on os arch
- int8,16,32,64
- NaN not a number
- Natural alias for range[0, ..high(int): useful for documentation/debugging/guards
- NegInf !inf
- PFloat32 alias for ptr float32
- PFloat64 alias for ptr float64
- PInt32 alias for ptr int32
- Pint64 alias for ptrint64
- Positive alias for range[1, ..high(int): useful for documentation/debugging/guards
- SomeFloat matches all float types
- SomeInteger matches SomeSigned|UnsignedInt
- SomeNumber matches SomeInteger|Float
- SomeSignedInt matches all signed integer types
- SomeUnsignedInt matches all unsigned integer types
- uint: unsigned integers, 32/64 bit depending on system,
- uint8,16,32,64
reference types
- ptr generic untraced pointer
- ref generic traced pointer
reference procs
- addr Take the address of a memory location
- owned
- unown
- disarm
misc types
- typedesc meta type denoting a type description, e.g. in a proc signature to pass in a type
- nil
- void
- auto for type inference