Opcode 3: Cell Check#
Syntax#
Opcode 3 implements the idiomatic ? wut cell check operator, which tests whether a noun is a cell.
*[a 3 b] ?*[a b]
Explanation#
Opcode 3 tests whether the product of formula b is a cell or an atom. It returns 0 (yes) if it’s a cell, 1 (no) if it’s an atom.
Evaluate
bagainst the subject to produce a noun.Test if that noun is a cell.
Return 0 if cell, 1 if atom.
One implication of nouns is that an easy way to tell data apart is by their structure:
?[a b] 0
?a 1
? wut is useful to ask whether a given noun is a cell or an atom. (Like C’s int main() return type and error codes, 0 means TRUE and 1 means FALSE.)
(Opcode 5 is closely related, as it tests whether one noun is equal to another.)
Opcode 3 is used for type discrimination (by structure before pattern matching) and for validating noun data shapes.