nim-wiki/Tips-and-tricks.md

32 lines
1008 B
Markdown

* Use "nim check myfile.nim" to check your program for errors, without code generation. This makes the process quicker.
## Using reserved words as identifiers
You can use the slanted quote string syntax if you need to use a reserved word as an identifier: ``var `type`: int``
## Tricks with conditional compilation
```nimrod
when defined(useSomeFeature):
const someSubFeature = true
type ID_Type = int32
var defaultUserName = "Frank"
else:
type ID_Type = int16
var defaultUserName = "Molly"
# `when` does not open a new scope, so `ID_Type` and `defaultUserName`
# are available here.
when isMainModule:
#this code is ran only when this module is the main compilation module
echo "This module was compiled on ", CompileDate, " at ", CompileTime
```
#### Defining `useSomeFeature`
* Do it when you compile: `$ nim c -d:useSomeFeature myApp`
* Put it in the local `nim.cfg` file `define:useSomeFeature`
## How do I echo in a ``{.noSideEffects.}`` proc?
You can use ``debugEcho`` for this.