-
Notifications
You must be signed in to change notification settings - Fork 0
Introduction
Intent is a low level totally functional programming language. Totally functional means that termination of an expression is guaranteed. Low level means that this is not a language intended for human consumption, rather it is a simple language to compile to and to execute efficiently. Intent is inspired by J and Nock.
Intent is a set of combinator rules, an interpreter can execute code simply by matching the current state to the left of a rule, and replacing it with the right. If something on the right is contained within parentheses that indicates some evaluation has to happen, e.g. (a + 1) indicates that the value of a + 1 should be calculated and put into the expression.
Every value in an expression is either a cell or an atom. A cell is a pair of values, denoted as [a, b]. An atom is either an integer (infinite range, possibly negative) or an Error. All calculations involving an Error value produce an Error value.
# Querying expressions, is it a cell or an atom?
kind? [a, b] => 1
kind? a => 0
# Basic Mathematics on signed integers
math- [a, b] => (a - b)
math- a => (-a)
math- [[a, b], c] => [math- [a, c], math- [b, c]]
math- [a, [b, c]] => [math- [a, b], math- [a, c]]
math- [[a, b], [c, d]] => [math- [a, c], math- [b, d]]
math= [[a, b], [c, d]] => math= [math= [a, c], math= [b, d]]
math= [a, a] => 1
math= [a, b] => 0
math= a => Error
# Cell addressing
cell> [a, b] => [b, a]
cell> a => a
# Dispatching
eval! [0, a] => kind? a
eval! [1, a]] => math- a
eval! [2, a]] => math= a
eval! [3, a]] => cell> a
# Control Flow
eval! [4, [a, [b, c]] => eval! [ eval! [a, b], eval! [a, c] ]
eval! [5, [0, [b, c]]] => b
eval! [5, [1, [b, c]]] => c
# Escape Hatch
eval! [6, [a, b]] => b