receq

A generator for comparison of recursive ref object types

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.1.1
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-08-10 05:37

Tags

Authors

  • Joel Lienhard

Installation

nimble install receq
choosenim install receq
git clone https://github.com/choltreppe/nim_receq

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
receq - - - - - - -

Dependencies

Package Version Optional
nim >= 1.6.4 No

Source

Repository https://github.com/choltreppe/nim_receq
Homepage https://github.com/choltreppe/nim_receq
Registry Source nimble_official

README

RecEq

receq defines the ==* and !=* operator to recursively compare 2 ref objects.
It also works for not recursive and mutual recursive types.
ref types that are no objects just get derefferenced and compared with ==

Litle Example

more can be found in the tests

type Tree = ref object
  val: int
  case isLeaf: bool
    of false: left, right: Tree
    else: discard

func val(x: int ): Tree = Tree(isLeaf: true, val: x)
func val(x: Tree): Tree = x

func tree(l: int|Tree, x: int, r: int|Tree): Tree =
  Tree(isLeaf: false, left: val l, val: x, right: val r)

assert: val(1) ==* val(1)
assert: val(1) !=* val(2)
assert: val(1) !=* tree(1, 2, 3)
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) ==* tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9))
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) !=* tree(tree(1, 2, 3), 4, tree(tree(6, 6, 7), 8, 9))
assert: tree(tree(1, 2, 3), 4, tree(tree(5, 6, 7), 8, 9)) !=* tree(tree(1, 2, 3), 4, tree(5, 8, 9))