src/nodejs/jschainedcomparisons

    Dark Mode
Search:
Group by:

  • Chained Comparisons for Nim, inspired by Python.

Example: cmd: -b:js -d:nodejs

import src/nodejs/jschainedcomparisons
let x = 6
let y = 2
let z = 2
doAssert not bool{ 4 < y < x < z <= 10 }
doAssert bool{ y == z == 2 }
doAssert not bool{ 1 < y != 2 }
doAssert bool{ 4 < x }  # Works Ok for 1 comparison too.
doAssert bool( 4 < x )  # Ignored, untouched.

Macros

macro `{}`(lhs, rhs: untyped): untyped
Example:
echo bool{ 4 < cat < dog < fox <= 10 }

Expands to:

echo 4 < cat and cat < dog and dog < fox and fox <= 10