Opcode 5: Equality Check

Contents

Opcode 5: Equality Check#

Syntax#

Opcode 5 implements the idiomatic = tis equality operator, which tests for deep equality between two nouns.

*[a 5 b c]          =[*[a b] *[a c]]

Explanation#

Opcode 5 tests whether the products of formulas b and c are structurally identical. It returns 0 if equal, 1 if not.

  1. Evaluate b against the subject to produce noun l.

  2. Evaluate c against the subject to produce noun r.

  3. Return 0 if l and r are identical nouns, 1 otherwise.

=[a a]              0
=[a b]              1

Like opcode 3, = tis checks by structure, and also by value. Equality is deep structural comparison: two cells are equal iff their heads are equal and their tails are equal.

:subject 42
Subject set to: 42
[5 [0 1] [1 42]]
0
:subject [42 43]
Subject set to: [42 43]

Two common patterns recur. The first checks whether a computed noun is equal to a specific target constant noun:

[5 [0 2] [1 42]]
0

The second compares two slots in the subject to see if they hold equal values:

[5 [0 2] [0 3]]
1
[5 [4 0 2] [0 3]]
0