Back to Front and Beyond
Based on a true story
Programming Languages
Originally created to give instructions to computers
Machine Code -> Assembly Language -> Cobol, Fortan, LISP, etc.
Added abstractions, hiding things at each step.
A Language for the Backend
Rewarding to pick up. Smooth learning curve.
Efficient programs.
As much help as possible to avoid bugs.
And point directly to them when they occur.
Multi-threaded.
A Language Checklist
What paradigms to support?
What abstractions over those paradigms?
What data abstractions?
How to implement the semantics?
What libraries can be used?
What tooling is available?
Concepts
Toccata has
record - deftype
procedure - defn
closure - fn
thread - future
single assignment - promise
cell (state) - agent
named state - top level agent
Concepts
Toccata does not have
unification
search
solver
by-need sync
continuation
name (unforgeable constant)
nondeterministic choice
port (channel)
sync on partial termination
clocked computation
local cell
log
observable non-determinism
What Abstractions?
Hide details behind an interface.
Main activity in programming is decomposing problems and composing solutions
Category Theory!! (but without the vocabulary)
What Abstractions?
Hide details behind an interface.
Main activity in programming is decomposing problems and composing solutions
Category Theory!! (but without the vocabulary)
But CT isn’t enough, especially for data abstractions.
What Abstractions?
Composition - Monoid
Container - Category Theory
Collection - Basic Data Abstractions
Seqable - Ordered Collections
Indexed - Ordered Random Access Collection
Associative - Keys to Values
How is the runtime implemented
Basic data types - Integer, String, Symbol
“Simple” Containers - Maybe, Promise
Immutable Data Structures - List, Vector, HashMap
Concurrency - Future, Agent
How is the runtime implemented
Written in C
Reference Counting Garbage Collection
That allows for Tail Call Optimization
Knows exactly when a value is no longer referenced.
Beat Haskell and Ocaml in mem usage on simple benchmark
Can automatically use mutation instead of copying on immutable data structs.
Can manage resources other than memory.
Libraries
Possible to use any lib with C bindings
But not trivial (room for improvement)
“Free as in puppies”
Tooling
Compiler produces C code.
LLVM (or GCC) produces executable.
Source level debugging using LLDB through use of ‘#line’ C macro.
Other tools in the C ecosystem for profiling, etc.
Types
Dynamic typing is great for prototyping and getting something running
Static typing is great for catching some bugs and preventing regressions
Gradual typing aims for the best of both
Language for the front end
WASM happened
Using Emscripten tool chain, worked the first time.
Single threaded only (until Spectre gets fixed)
But no garbage collector. No problem!
Very primitive interface between Javascript and WASM code.
Have to marshal/un-marshal data structures on each side.
WASM GC has to play nice with Javascript GC.
Language for the front end
A module to cross the WASM / JS chasm
A module to work with the DOM
A module to produce HTML/CSS
Whither React, Angular, etc.?
A provocative idea that Web Components will replace frontend frameworks.
NPM? (remember the puppies)
Language for the beyond
Parser uses a grammar to produce an AST from raw text
C code is generated from AST
What if … we did something else with the AST
How hard could it be?
All the grammar and parsing is in libraries.
The compiler already has them. An interpreter is just another module.
Compiled Code
Interpreted Code
(defn bar [z] …)
(defn baz [q] ... )
(defn foo [x y]
(bar x (baz y)))
foo, bar, baz
Compiled Code
Interpreted Code
(defn bar [z] …)
(defn foo [x y]
(bar x (inc y)))
foo, bar
inc
Compiled Code
Interpreted Code
(defn foo [x]
(inc x))
(map some-vect foo)
(map …)
map-vector
foo
inc
Compiled Code
Interpreted Code
(defprotocol BarProto
(bar [x y]))
(deftype BazType [x y]
BarProto
(bar [x y] ...))
(defn foo [baz]
(bar baz 8))
foo, bar, baz
Compiled Code
Interpreted Code
(deftype BazType [x y]
Stringable
(string-list [_]
...))
(print-err ‘baz (BazType 8 “Bazzer”))
print-err
string-list
Language for the beyond
Compiler / Interpreter has all libs to work with Toccata source.
Easily write scripts to create tooling
Language for the beyond
Using WASM should be able to write serverless functions
With some compiler directives, can produce smaller binaries for embedded devices.
Concepts
Toccata has
record - deftype
procedure - defn
closure - fn
thread - future
single assignment - promise
cell (state) - agent
named state - top level agent
What Abstractions?
Composition - Monoid
Container - Category Theory
Collection - Basic Data Abstractions
Seqable - Ordered Collections
Indexed - Ordered Random Access Collection
Associative - Keys to Values
Questions?