A declarative, (almost) statically typed, stack programing language. Inspired by the FMC, FMCt, and Forth.
Table of Contents
You can play in the spci
interpreter or run files with the spc
interpreter.
There are many ways of building the project.
-
Run
nix build
inside the repository -
Run
./result/bin/spc
for the interpreter orrlwrap ./result/bin/spci
for the interactive interpreter. Note that I recommend you userlwrap
to get the nice line wrpapping.
- Run
cabal run spc
for the interpreter orrlwrap cabal run spci
for the interactive interpreter.
- Run
stack run spc
orrlwrap stack run spci
Let's imagine we have an infinity of stacks, each having a name. From this
infinity of stacks - to make things easier we choose two. One stack, our main
one, is called @γ
, and another is called @_
(or the Default location).
Observe that we know they are location due to their name starting with an @
.
If we wanted to use the stack at location foo
we would simply refer to stack
@foo
. Now, let's imagine we have a machine that moves terms in this
Space
. Say we wanted to put the number 3
onto the main stack, the way to do
so is simply to give the term 3 to our Space
machine and it will put it on the
stack. This is done simply by evaluating the number 3 like so:
> 3
At the end of evaluating this term our stacks would look as follows:
@γ: 3
@_:
Cool, so we've essentially pushed the number 3 to the main stack. What if we
evaluated another number, say 5
, like so:
> 5
Well then the term would pe pushed to the main location and the term would be evaluated again, leading to the following memory:
@γ: 5;3
@_:
What if we wanted to add these two numbers. For that Space
offers us the
function +
with the type {int,int} -> {int}.
> +
and the memory is now:
@γ: 8
@_:
To move 8
from the main stack to the default location, we now use another
special function, namely scoop
with the operator !
. Upon evaluating !
the
Space
machine picks up the first term and pushes it to the default location.
@γ:
@_: 8
- Ch <-> Char
- {} <-> Void
- Z <-> Integer
- [{Z} -> {Z}] <-> Integer -> Integer
- [{} -> {Z}] <-> Void -> Integer
To see some examples, have a look at the test files.
-
a module system
-
a step debugger that steps through the the term as it executes.
-
make a program that actually does something - check examples.
Haskell | Space |
---|---|
x = 2 | [2]; |
[2] (space notation) | |
f x = x + 2 | [;2;x;+]; |
z = f 2 | 2;f; |