1 Cordial Reference
jess edited this page 2026-04-15 09:38:07 -07:00

Cordial Reference

Eval lines

Prefix Result kind
/= Inline
/=| Table
/=\ Tree
/= 2 + 3                    // → 5
/=| @Budget
/=\ [[1,2],[3,[4,5]]]

Literals

Numbers

42
3.14
-7
1e-9
1E+3
.25

Strings

"hello"
"tab\there"
"quote: \"yes\""

Escapes: \n, \t, \\, \".

Booleans

true
false

Arrays

[1, 2, 3]
[1, "two", true]
[]

Ranges

0..5                        // [0, 1, 2, 3, 4]

Half-open. Capped at 10,000 elements.

SPICE values

Requires use spice.

100nF                       // [1e-7, "F"]
80Hz                        // [80, "HZ"]
10µF                        // [1e-5, "F"]
1n                          // [1e-9, ""]

Implicit multiplication

2pi                         // 2 * pi
3x                          // 3 * x
4(a + b)                    // 4 * (a + b)
2 pi                        // PARSE ERROR

Operators

Arithmetic

a + b
a - b
a * b
a / b
a % b
a ^ b           // right-associative
-a

Comparison

a == b      a != b
a <  b      a >  b
a <= b      a >= b

Logical

a && b      or      a and b
a || b      or      a or  b
!a          or      not a

Short-circuit on &&/and and ||/or.

Strip operator

~true                       // 1
~false                      // 0

Spice [n, unit]n. Bool → 0 / 1.

is type-check

1 is int                    // → true
1.5 is int                  // → false
1.5 is float                // → true
true is bool                // → true
[1,2] is array              // → true
"x" is str                  // → true

Cell assignment

Statement-level only.

@Budget:A2 = "Housing"
@Sales:C3 = 1500

Statements

let

let x = 5
let y = 2 + 3

let with value-type annotation

let x: int = 42
let y: float = 3.14
let z: int = 3.7            // ERROR
let b: bool = 0
let s: str = 42

Value types: int, float, bool, str.

let with unit annotation

use spice
let cap:  F  = 22n          // [2.2e-8, "F"]
let freq: HZ = 60           // [60, "HZ"]
let h     = 10
let hh: H = h               // [10, "H"]

Reassignment

let x: int = 5
x = 10                      // ok
x = 3.7                     // ERROR

let f(x) = expr

let double(x)  = x * 2
let hypot(a, b) = sqrt(a^2 + b^2)

fn

fn area(w, h) {
    w * h
}

fn area_typed(w: float, h: float) -> float {
    return w * h
}

fn charge(c: F, v: V) -> J {
    0.5 * c * v^2
}

Function inversion

Math form:

let solve_l(f0, c) = l where lc_freq(l, c) = f0

Macro form:

let solve_l = solve!(l, lc_freq)
let solve_l = solve!(l from lc_freq)

if / else if / else

if x > 0 {
    y = 1
} else if x < 0 {
    y = -1
} else {
    y = 0
}

while

Capped at 10,000 iterations.

let i = 0
while i < 10 {
    i = i + 1
}

for … in …

for i in 0..10 {
    sum = sum + i
}

for x in [1, 2, 3] {
    y = y + x
}

return

fn first_positive(a, b) {
    if a > 0 { return a }
    return b
}

use

use spice
use other_block::my_fn
use utils::*

Expressions

Function calls

sin(x)
sum(@Budget:B2:B20)
my_fn(a, b, c)

Indexing

arr[0]
arr[-1]
"hello"[1]                  // "e"

Cell references

@Budget
@Budget:A1
@Budget:A2:A10
@Budget[A2:A10]
@Calculations::Revenue:B1
A1                          // bare — in a cell formula

Built-in functions

Trigonometric and transcendental

Function
sin, cos, tan radians
asin, acos, atan inverse
sqrt square root
abs absolute value
ln natural log
log base-10 log

Unit-transparent.

sin(pi/2)                   // 1
sqrt(16)                    // 4

Rounding

floor(3.7)                  // 3
ceil(3.1)                   // 4
round(3.14159, 2)           // 3.14
round(1234, -2)             // 1200

Aggregates

Function
sum
avg
min
max
count
std_devp population stddev
std_devs sample stddev (≥ 2 values)
sum(@Budget:B2:B20)
avg([1, 2, 3, 4])           // 2.5
std_devs(@Sales)

Array and string

Function
len(x) length of array or string
range(start, end) half-open integer range as array
push(arr, val) append, returns new array
len([1, 2, 3])              // 3
len("hello")                // 5
range(0, 5)                 // [0, 1, 2, 3, 4]
push([1, 2], 3)             // [1, 2, 3]

Built-in constants

Name Value
pi 3.141592653589793

Type system

Value types

int, float, bool, str.

Coercion Result
3.0 → int 3
3.7 → int error
0 → bool false
1 → bool true
2 → bool error
42 → str "42"
"42" → int 42
"3.7" → int error

Unit types

Any identifier that isn't a value-type is a unit label. Spice-tagged values live as [scalar, "UNIT"] arrays.

Resource limits

Guard Limit
Loop iterations 10,000
Call depth 256
solve! iterations 100
solve! epsilon 1e-10

See also