nock

package module
v0.0.0-...-05b9fae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 2 Imported by: 0

README

nock

GoDoc Go Report Card

go get github.com/lukechampine/nock

nock implements a simple Nock interpreter, according the spec available at https://urbit.org/docs/nock/definition.

This interpreter assumes that its input is well-formed, and does not support atoms larger than a machine int.

Example

decrement := nock.Parse(`[42 [8 [1 0] 8 [1 6 [5 [0 7] 4 0 6]
            [0 6] 9 2 [0 2] [4 0 6] 0 7] 9 2 0 1]]`)
program := nock.Cell(nock.Atom(42), decrement)
result := nock.Nock(program)
println(result) // 41

Documentation

Overview

Package nock implements a simple Nock interpreter, according the spec available at https://urbit.org/docs/tutorials/nock/definition/.

This interpreter assumes that its input is well-formed, and does not support atoms larger than a machine int.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Noun

type Noun struct {
	// contains filtered or unexported fields
}

A Noun is an atom or a cell. An atom is any natural number. A cell is any ordered pair of nouns.

func Atom

func Atom(i int) Noun

Atom returns an atom with value i.

func Cell

func Cell(head, tail Noun) Noun

Cell returns a cell that pairs head with tail.

func Loobean

func Loobean(b bool) Noun

Loobean returns the atom 0 if b is true, and the atom 1 if b is false.

func Nock

func Nock(n Noun) Noun

Nock evaluates the nock function on n using the latest Nock version.

func Nock4

func Nock4(n Noun) Noun

Nock4 evaluates the nock function on n using Nock 4.

func Nock5

func Nock5(n Noun) Noun

Nock5 evaluates the nock function on n using Nock 5.

func Parse

func Parse(s string) Noun

Parse parses a Nock program.

func (Noun) Head

func (n Noun) Head() Noun

Head returns the head of n, which must be a cell.

func (Noun) IsAtom

func (n Noun) IsAtom() bool

IsAtom returns true if n is an atom.

func (Noun) IsCell

func (n Noun) IsCell() bool

IsCell returns true if n is a cell.

func (Noun) Num

func (n Noun) Num() int

Num returns the integer value of n, which must be an atom.

func (Noun) String

func (n Noun) String() string

String implements the fmt.Stringer interface.

func (Noun) Tail

func (n Noun) Tail() Noun

Tail returns the tail of n, which must be a cell.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL