Module ladder

Search:
Group by:

Ladder logic control blocks implemented with Nim macros, using standard contact-coil semantics.

import ladder

var
  x = true
  y = false
  z = false

contact x:
  echo "hello, world!"
  coil y

echo y    # true

contact(x and y):
  coil z

echo z    # true

contact(not z):
  echo "this text will not be printed."
  coil x

echo x    # false

Macros

macro contact(cond, contents: untyped): untyped
A contact block takes a condition cond of boolean type. If the boolean is true, code inside the block will be executed and all coil s contained by the block will be set to true. If cond is false, coils contained by the contact will be set to false, and no other code inside the contact will run.
macro coil(contents: untyped): untyped
coil may only be called inside a contact block. coil takes one argument- a boolean variable. The boolean is set if the surrounding contact is true, and cleared when the surrounding contact is false.