Skip to content

Commit

Permalink
version 0.0.2.1: tidy-up machine restart + examples and presentation.
Browse files Browse the repository at this point in the history
Revert: Some changes we don't need.

This reverts commit 1754921cb983168dc090ca402613fa3faaf6f1f0.
  • Loading branch information
cstml committed Dec 29, 2023
1 parent fc350ea commit 4219f4a
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 63 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# spacelang

A concatenative, stack based language with async capabilities.
A (yet another) concatenative, stack based language (but) with async
capabilities.

## Status

Expand Down
1 change: 1 addition & 0 deletions example/add_2.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slurp slurp + .
180 changes: 180 additions & 0 deletions example/presentation.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
["
" ,] [newPage] ^
[(slurp :rs newPage ! )] [waitForCharacter] ^

[:s] [results] ^

[ print waitForCharacter ! ] [printThenWait] ^
"Hello and welcome to TechDive presentation of spacelang" ,
waitForCharacter !

"What is spacelang you ask?" ,
waitForCharacter !

"It is a stack based programming language (akin to Forth), that: " , waitForCharacter !
"Pause for dramatic effect." , waitForCharacter !
"- is simpler (?)," , waitForCharacter !
"- proposes a novel async model (as far as stack languages go)," , waitForCharacter !
"- leverages lazy evaluation," , waitForCharacter !
"- has some interesting features," , waitForCharacter !
"- meta-programming is built-in and part of the normal functioning of the language." , waitForCharacter !

"We have a stack to which we can push Terms:
We simply push them by writing them down:" ,

"> 1 2 " . waitForCharacter !

"In this example the interpreter reads '1' pushes it to the stack, then reads
'2' and pushes it to the stack resulting in:" . waitForCharacter !
1 2 results ! waitForCharacter !

"The evaluation model of the language is a key aspect of what makes it special.
Left to right, sequential evaluation ensures that our programs are confluent,
even with the addition of effects." .

waitForCharacter !

"Our terms can be numbers, strings, booleans, words, or thunks." ,
"> 1 'strings' true + [thunk]" ,
waitForCharacter !

"Words, and terms in spacelang are from a type perspective arrows, which means
that they compose. Let's use the following notation:
- '(input -- output)'
- capitalised for defined types
- uncapitalised for variables

Therefore we have
1 : ( -- Number)
+ : ( Number Number -- Number)
etc.

This 'arrow' property of terms means that any term is a function, and it also
gives us the concatenative property of the language. In essence a sequence of
two terms is a composition." , waitForCharacter !

"As the TechDive is a bit short, to cover 'Principia Mathematica', we'll accept
that numbers are primitives that evaluate to themselves. As seen before. So are strings.

From a type perspective we say
'a' : ( -- String)
1 : ( -- Number)
" ,
waitForCharacter !

"The first notable exception are words. Words evaluate to their binding (whatever
that is). The language provides some built in words:
- numerical operations: + - / * < <= etc.
- machine operations: :h :r :debug :m : rs etc.
- memory operations: ^
- evaluator operations: !
- inter-machine operations: $",
waitForCharacter !

"But the funkiest one is the thunk which we write by enclosing a term within
square brakets, like so:
> [1 3 +]

Which has the type:
[1 3 +] : ( -- ( -- Number))

So what's going on here?
", waitForCharacter !

"We force evaluation of a thunk with the operator '!', which behaviour we can
describe with the term

((a) -- a)
",
waitForCharacter !

"We can bind terms to words with the word `^`, together with thunks we can now
define our own funky words.

> [1 +] [addOne] " ,
waitForCharacter !

"Word bindings have a notion of scope, therefore if we do the following:

> ( [1 +] [addOne] 2 addOne ) 4 addOne

The program will crash and burn as addOne is not defined/bound outside the scope
defined by the parens.

As the parens themselves are terms - we can use scope local to our thunks as so
> [ ([x] ^) ]
A term which would pop x and discard it essentially.
" , waitForCharacter !

"Last thing to mention is that spacelang is more or less a language to
orchestrate a machine. Imagine many such machines each with their own address.
Here is where $ operator comes into play.
This is the async model of space.
" , waitForCharacter !

"Enough talking, let's find bugs!" , waitForCharacter !

"The End." , waitForCharacter !
"*Pause for aplause.*" , waitForCharacter !

"Any questions?" ,
8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
pkgs = import nixpkgs {
inherit system;
};
ncurses = pkgs.ncurses;

compiler = pkgs.stdenv.mkDerivation {
name = "compiler";
Expand All @@ -17,13 +18,16 @@
sbcl
gnumake
lispPackages.quicklisp
ncurses
];

shellHook = ''
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ncurses}/lib;
'';
};
in
{
defaultPackage = compiler;


}
);
}
8 changes: 7 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ bin/spci: bin/ $(lisp_files) $(asd_files)
--eval '(ql:quickload "spacelang")' \
--eval '(asdf:load-system "spacelang")' \
--eval '(use-package :spacelang)' \
--eval "(sb-ext:save-lisp-and-die #p\"bin/spci\" :toplevel #'space! :executable t)"
--eval "(sb-ext:save-lisp-and-die #p\"bin/spci\" :toplevel #'space! :executable t)"

bin/:
mkdir bin

.PHONY: DockerRun

DockerRun:
docker build . -t spacelang
docker run -it spacelang
2 changes: 1 addition & 1 deletion parser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
(.read (.number))
(.read (.slurp))
(.read (.word))
(.read (.opp))
(.read (.dict-up))
(.read (.dict-down))
(.read (.cons))
(.read (.opp))
(.read (.send))
(.read (.bind-term))
(.read (.eval-term))
Expand Down
Loading

0 comments on commit 4219f4a

Please sign in to comment.