variables and globals
TLDR
- catchall for global keywords/procs/types/etc not specified in other files
- anything like BLAH= can be written BLAH =
- the former enables you to define/overload operators via 'proc woop=bloop: doop = toot'
- converts are listed here because their purpose is implicit type coercion
- additional type features are covered in structuredContainers.nim
- you can call clear on pretty much anything
links
TODOs
- blah.reset a thing to its default value
var
- runtime mutable global var
let
- runtime immutable
const
- compile-time evaluation cannot interface with C
- there is no compile-time foreign function interface at this time.
- consts must be initialized with a value
- declares variables whose values are constant expressions
static
- static represents a compile time entity, whether variable, block or type restriction
- staticT meta type representing all values that can be evaluated at compile time
- all static params are treated as generic params, thus may lead to executable bloat (see generics)
eval
- eval executes a block of code at compile time
stropping
- enable use of keywords as operators
auto
- auto only for proc return types and signature parameters
- parameter auto: creates an implicit generic of proc[x](a: x)
- return auto: causes the compiler to infer the type form the routine body
type casts
- cast operator forces the compiler to interpret a bit pattern to be of another type
- i.e. interpret the bit pattern as another type, but dont actually convert it to the other type
- only needed for low-level programming and are inherently unsafe
type coercions
- aka type conversions sometimes in docs, but always means coercion
- type coercions preserve the abstract value, but not the bit-pattern
- allocCStringArray creates a null terminated cstringArray from
- chr(i): convert 0..255 to a char
- cstringArrayToSeq
- only widening (smaller > larger) conversions are automatic/implicit
- ord(i): convert char to an int
- parseInt/parseFloat from a string
- toFloat(int): convert int to a float
- toInt(float): convert float to an int
- toOpenArray
- toOpenArrayByte
type inspection
- type(x): retrieve the type of x, discouraged should use typeof
- typeof(x, mode = typeofIter): retrieve the type of x
- typeOfProc: retrieve the result of a proc, i.e. typeof x, typeOfProc
- TypeofMode: enumtypeofProc|typeofIter second param to typeof
echo/repr
- roughly equivalent to writeLine(stdout, x); flushFile(stdout)
- available for the JavaScript target too.
- cant be used with funcs/{.noSideEffect.} (use debugEcho)
important globals
- nimvm: true if current execution context is compile time
Procs
proc doubleFloat(x: float): float {....raises: [], tags: [], forbids: [].}
- Source Edit