layout/if

Symbol: layout/if

General block syntax: Reader and layout syntax.

Use-case: Multi-branch conditional with optional elif and else peers. Lowers to compile/cond.

Behaviour: Accepts optional peer blocks elif and else. After the if body, the reader gathers contiguous peer blocks at the same indent as the if header (including when if/else appears nested inside another block’s body) and expands them with the primary through apply_layouts. Produces (cond (TEST BODY) (TEST BODY) ... (else: BODY)). Rules: elif cannot follow else; else takes no arguments; only one else is allowed.

Syntax:

if COND:
  BODY
elif COND:
  BODY
else:
  BODY

Examples:

if x:
  y
;; -> (cond (x y))

if x:
  a
elif y:
  b
else:
  c
;; -> (cond (x a) (y b) (else: c))

Also: macro if.