A small, base-10 language built around Spectons — values that hold probability distributions instead of single numbers.
SPECTRA isn't binary. A variable can be:
- sharp —
5("state 5, period") - ranged —
3..7("somewhere in 3 through 7") - wave-shaped —
~{0:0.1, 1:0.7, 2:0.2}~("70% at state 1, 10% at state 0, 20% at state 2")
The language treats all three forms as first-class values, and two operators make the rest interesting:
a.resonate(b)— keeps the states where bothaandbcarry weight. Like an AND that amplifies agreement.a.interfere(b)— cancels the states whereaandboverlap. Like an XOR that erases sameness.
With .peak() (the most likely state) and .entropy() (how unfocused
the value is), you can write probabilistic logic that reads almost
like normal code.
s = ~{0:0.1, 1:0.7, 2:0.2}~
print("peak: " + tostr(s.peak())) # 1
print("entropy: " + tostr(s.entropy())) # around 0.80
See examples/ for more, and
SPECTRA_LANGUAGE_REFERENCE.md for
the full language reference.
A few things you can express in 20–40 lines of SPECTRA that come out awkwardly in scalar-only languages:
-
Composing moods. Take four neuromodulator levels (dopamine, norepinephrine, serotonin, acetylcholine) as Spectons. Then
resonateandinterferegive you an overall affective state: approach vs. avoid, focused vs. scattered, sharp vs. diffuse. -
Picking the right goal. Build a Specton from current attention, one from each candidate goal, then resonate every pair. The goal whose resonance peaks sharpest wins — and the entropies tell you whether the choice was decisive or a coin flip.
-
Resolving conflicting evidence. Two sources disagree on a fact. Each side's trust, recency, and confidence resonate together into a verdict Specton. The side whose verdict is higher-peaked and lower-entropy is the one to believe — and if both come out diffuse, you know to escalate instead of guessing.
In each case the win isn't the operator — it's that the entropy and peak of the result tell you not just what the answer is, but how confident the language is in it.
build.bat
spectra.exe examples/hello.sp
cmake -B build
cmake --build build
./build/spectra examples/hello.sp
make test # runtime tests (C)
python tests/run_all.py # language tests (.sp files)
Licensed under the Apache License, Version 2.0 — see LICENSE. Free to use, modify, and redistribute, including commercially, with attribution.
Questions or suggestions: open an issue on this repo.