src/bookofnim/helloworld/modules/ifWhenCase

Search:
Group by:
Source   Edit  

branching: if when case

TLDR

  • new scopes are introduced immediately aftered the keywords (e.g. if, elif, etc)
    • except for when statements/expressions
  • use whens for completely removing sections of code at compile time
  • all can be used as expressions and the result assigned to a var
  • case statement branches should be listed in order of most expected

branching TODOs

when

  • a compile time if statement
  • the condition MUST be a constant expression
  • does not open a new scope
  • only the first truthy value is compiled

case

  • similar to if, but represents a multi-branch selection
  • supports strings, ordinal types and integers
    • ints/ordinals can also use ranges
    • the of part must match the value type
  • can also use elif, else branches
checks whether x can be compiled without any semantic error. useful to verify whether a type supports some operation:whether x is declared at compile timechecks current scope at compile time

Vars

numCase = 50.345
Source   Edit  
typeSupportBlah = "halb"
Source   Edit  
whichVerse: string = "real world"
Source   Edit  

Procs

proc positiveOrNegative(num: int): string {....raises: [], tags: [], forbids: [].}
Source   Edit