Lexical Structure and Syntax Basics

addr and as asm bind block break case cast concept const continue converter defer discard distinct div do elif else end enum except export finally for from func if import in include interface is isnot iterator let macro method mixin mod nil not notin object…

3.1 Indentation and Statements

Blocks are defined by indentation (spaces only, tabs are not allowed). The convention is 2 spaces.

One statement per line. ; separates statements on one line.

Long expressions can continue after an operator, (, or ,.

3.2 Comments

# single-line comment
## documentation comment (appears in generated docs)
#[
  multi-line comment
  #[ can be nested ]#
]#

3.3 Identifiers and Style Insensitivity

Letters, digits, underscores. Must start with a letter. No consecutive or trailing underscores.

Style insensitive: fooBar, foo_bar, and foobar are the same identifier. The first character is case-sensitive: Foo ≠ foo.

Conventions: camelCase for variables and procs, PascalCase for types, constants in camelCase or PascalCase.

Stropping: use backticks to use keywords as identifiers: ` var type = 5 `.

3.4 Keywords

addr and as asm bind block break case cast concept const continue converter defer discard distinct div do elif else end enum except export finally for from func if import in include interface is isnot iterator let macro method mixin mod nil not notin object of or out proc ptr raise ref return shl shr static template try tuple type using var when while xor yield

3.5 Literals

let
  dec = 1_000_000          # underscores for readability
  hex = 0xFF
  oct = 0o17
  bin = 0b1010
  f = 3.14
  e = 1.5e-3
  i8 = 127'i8              # type suffix
  u = 42'u32
  f32 = 1.0'f32
  ch = 'a'
  s = "string"
  raw = r"C:\path\no\escapes"
  multi = """Triple
quoted"""