1 of 31

Back to Front and Beyond

Based on a true story

2 of 31

Programming Languages

Originally created to give instructions to computers

Machine Code -> Assembly Language -> Cobol, Fortan, LISP, etc.

Added abstractions, hiding things at each step.

3 of 31

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.

4 of 31

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?

5 of 31

6 of 31

7 of 31

Concepts

Toccata has

record - deftype

procedure - defn

closure - fn

thread - future

single assignment - promise

cell (state) - agent

named state - top level agent

8 of 31

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

9 of 31

What Abstractions?

Hide details behind an interface.

Main activity in programming is decomposing problems and composing solutions

Category Theory!! (but without the vocabulary)

10 of 31

11 of 31

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.

12 of 31

What Abstractions?

Composition - Monoid

Container - Category Theory

Collection - Basic Data Abstractions

Seqable - Ordered Collections

Indexed - Ordered Random Access Collection

Associative - Keys to Values

13 of 31

How is the runtime implemented

Basic data types - Integer, String, Symbol

“Simple” Containers - Maybe, Promise

Immutable Data Structures - List, Vector, HashMap

Concurrency - Future, Agent

14 of 31

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.

15 of 31

Libraries

Possible to use any lib with C bindings

But not trivial (room for improvement)

“Free as in puppies”

16 of 31

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.

17 of 31

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

18 of 31

19 of 31

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.

20 of 31

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)

21 of 31

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.

22 of 31

Compiled Code

Interpreted Code

(defn bar [z] …)

(defn baz [q] ... )

(defn foo [x y]

(bar x (baz y)))

foo, bar, baz

23 of 31

Compiled Code

Interpreted Code

(defn bar [z] …)

(defn foo [x y]

(bar x (inc y)))

foo, bar

inc

24 of 31

Compiled Code

Interpreted Code

(defn foo [x]

(inc x))

(map some-vect foo)

(map …)

map-vector

foo

inc

25 of 31

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

26 of 31

Compiled Code

Interpreted Code

(deftype BazType [x y]

Stringable

(string-list [_]

...))

(print-err ‘baz (BazType 8 “Bazzer”))

print-err

string-list

27 of 31

Language for the beyond

Compiler / Interpreter has all libs to work with Toccata source.

Easily write scripts to create tooling

28 of 31

Language for the beyond

Using WASM should be able to write serverless functions

With some compiler directives, can produce smaller binaries for embedded devices.

29 of 31

Concepts

Toccata has

record - deftype

procedure - defn

closure - fn

thread - future

single assignment - promise

cell (state) - agent

named state - top level agent

30 of 31

What Abstractions?

Composition - Monoid

Container - Category Theory

Collection - Basic Data Abstractions

Seqable - Ordered Collections

Indexed - Ordered Random Access Collection

Associative - Keys to Values

31 of 31

Questions?

http://toccata.io

@toccata_lang

Bibliography:

http://www.toccata.io/assets/Biblio.html