O'Reilly logo

Nim in Action by Dominik Picheta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nim Reference

Common constructs

const x = 5 Compile-time constant
let y = "Hello" Immutable binding
var z = [1, 2, 3] Mutable variable
proc name(param: int): ReturnType = body
method name(param: float): ReturnType = body
iterator items(list: seq[int]): int = body
template name(param: typed) = body
macro name(param: string): untyped = body
if x > 5: bodyelif y == "Hello": bodyelse: body case xof 5: bodyof 1, 2, 3: bodyof 6..30: body
for item in list: body for i in 0..<len(list): body
while x == 5: if y.len > 0: break else: continue try: raise errexcept Exception as exc: echo(exc.msg)finally: discard

Input/Output

echo(x, 42, "text") readFile("file.txt")
stdout.write("text ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required