src/bookofnim/helloworld/modules/blocks

Search:
Group by:
Source   Edit  

blocks

TLDR

  • blocks have a () syntax but we skipped it as its not idiomatic nim in this context
  • new scope introduced after the : symbol, and ends when the indentention returns to previous level
  • named blocks can be exited specifically with break blockName
  • like most other things, blocks can be expressions and assigned to a var
  • see loopIterator.nim for closureScope blocks

links

once blocks

  • are executed once, the first time they're seen by the compiler

Vars

alreadyExecuted`gensym2 {.global.} = false
Source   Edit  

Lets

myChar = block:
  var yourChar = 'a'
  if contains({'a', 'b', 'c'}, yourChar):
    echo ["yourChar was found ", yourChar]
  yourChar
Source   Edit  
sniper = "scope module"
is in the module scope, global to this module Source   Edit