Opcode 1: Constant

Contents

Opcode 1: Constant#

Syntax#

*[a 1 b]            b

Explanation#

In many respects, opcode 1 is the simplest conceivable Nock operation: it simply returns its argument b, ignoring its subject a entirely.

Opcode 1 is used to store data for use in later computations. This can either be conventional data as atoms (including byte arrays) and structured data in a cell format; or it can be Nock code itself, which can be retrieved and executed later using opcode 9.

:subject 42
Subject set to: 42
[1 1000]
1000

While you haven’t seen the full Nock specification for the other opcodes yet, observe how evaluating a stored noun with opcode 1 results in an executable Nock expression.

[1 4 0 1]
[4 0 1]

In this expression, we use opcode 2 to evaluate the noun stored in the subject [0 1], then we retrieve the constant code stored using opcode 1, and finally we execute that code with the result of the first evaluation as its subject. A bit roundabout, in this case, but it demonstrates how stored code can be executed later.

[2 [0 1] [1 4 4 4 0 1]]
45