Urbit wordmark
Blog
hamburger menu closed

Nockmas 2025: Day 9

12 days of Nockmas: Extend, opcode 8

2026-01-02

~lagrev-nocfep

nockmas day 9 extend image

On this ninth day of Nockmas, we will explore opcode 8, Extend and how Nock implements variable binding.

Opcode 8: Extend

Syntax

*[a 8 b c]          *[[*[a b] a] c]

Explanation

Opcode 8 pins a new value to the head of the subject, then evaluate the body. This is how Nock implements variable binding—the new value becomes accessible at address 2.

  1. Evaluate b against subject to produce a new value.
  2. Construct [new-value subject] as the extended subject.
  3. Evaluate c against the extended subject.

After opcode 8, addresses shift:

  • Address 2 → the new pinned value
  • Address 3 → the original subject
  • Address 6 → what was address 2
  • Address 7 → what was address 3

Opcode 8 extends the subject, while opcode 7 replaces it:

*[a 7 b c]  →  *[*[a b] c]       :: New subject is *[a b]
*[a 8 b c]  →  *[[*[a b] a] c]   :: New subject is [*[a b] a]

There are two primary patterns for using opcode 8. In the first, a local variable is bound for use in a computation:

*[data [8 [compute-value] [body-using-value-at-+2]]]

We start with our subject:

:subject 42

Output:

Subject set to: 42

And call a Nock 8 with the following formula:

[8 [1 41] [[0 2] [0 3]]]

Output:

[41 42]

The other, more complex, pattern is to pin a core and its arms to the subject for invocation later. We'll see this pattern in detail in opcode 9's discussion.

*[context [8 [1 battery] [9 2 [0 1]]]]

Join us tomorrow when we cover Nock 9, Invoke.

12 Days of Nockmas is an exploration of Nock, Urbit's instruction set architecture. This ISA is used by both Urbit and Nockchain, has interpreters written in many languages, with production versions in both C and Rust. The content of this series is drawn from the Nock language site. Visit the site for interactive code examples and more Nock related content.

XGithubTlonYoutubeGatherEmail