nim-wiki/Tips-and-tricks.md

32 lines
1008 B
Markdown
Raw Normal View History

2015-02-03 08:10:15 +00:00
* Use "nim check myfile.nim" to check your program for errors, without code generation. This makes the process quicker.
2013-01-24 17:03:20 +00:00
2013-01-25 21:18:55 +00:00
## Using reserved words as identifiers
2013-01-24 17:03:20 +00:00
2013-01-25 21:18:55 +00:00
You can use the slanted quote string syntax if you need to use a reserved word as an identifier: ``var `type`: int``
2010-09-14 10:11:11 +00:00
2013-01-25 21:18:55 +00:00
## Tricks with conditional compilation
2010-09-14 10:11:15 +00:00
2013-01-25 21:17:45 +00:00
```nimrod
2014-05-01 18:13:57 +00:00
when defined(useSomeFeature):
2010-09-14 10:11:11 +00:00
const someSubFeature = true
2014-05-01 18:13:57 +00:00
type ID_Type = int32
var defaultUserName = "Frank"
2010-09-14 10:11:11 +00:00
else:
2014-05-01 18:13:57 +00:00
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
2013-01-25 21:17:45 +00:00
```
2014-05-01 18:13:57 +00:00
#### Defining `useSomeFeature`
2015-02-03 08:10:15 +00:00
* Do it when you compile: `$ nim c -d:useSomeFeature myApp`
* Put it in the local `nim.cfg` file `define:useSomeFeature`
2014-05-01 18:13:57 +00:00
2013-01-25 21:18:55 +00:00
## How do I echo in a ``{.noSideEffects.}`` proc?
2013-01-25 21:17:45 +00:00
You can use ``debugEcho`` for this.