Building Your Own
Lisp
For Great Justice
@bodil
Make your own Lisp
A rite of passage.
I use X
You probably haven't heard of it.
The Perfect Language
is Clojure
is Haskell
BODOL
pure
immutable
homoiconic
typed
makes HN caremad
(ƒ fac
0 → 1
n → (* n (fac (- n 1))))
(ƒ map
f () → ()
f (head . tail) → (cons (f head)
(map f tail)))
Pick your language
as long as it's Clojure.
Instaparse
by Mark Engelberg
parsers for the people
just EBNF
or parser combinators
(ns ohai.instaparse
(:require [instaparse.core :as insta]))
Primitive Types
strings, numbers, booleans
symbols
cons cells
Elementary Functions
cons, car, cdr
cond, eq, atom
lambda, label, quote
Evaluation
primitive types evaluate to...
themselves
symbols evaluate to...
their bound values
functions evaluate to...
their results
eval()
program, environment in
result, environment out
(ns clap.if.you.love.monads)
(defn reduce-state
"Evaluate a list of state monad values in sequence, using the
provided initial state."
[state mvs]
(reduce (fn [[value state] next]
(next state))
[nil state]
mvs))
Dynamic Scope
When you invoke a function, pass it the scope at the point where it's called.
Lexical Scope
When you define a function, attach the scope at the point of definition.
This makes a closure.
Pattern Matching
run* that shit
(ns ohai.pattern-matching
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :as l :refer [run fresh ==]]))
;; (ƒ i-like-zeroes
;; 0 0 -> "double zeroes!"
;; 0 a -> "zero car"
;; a 0 -> "zero cdr"
;; a b -> "no zeroes"
This is your lisp on pattern matching
cons, car, cdr
cond, eq, atom
lambda, label, quote
Type System
shout if you like Robin Milner
(ns tapl.destroyed.my.mind
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :as l :refer [run fresh ==]]))
;; (ƒ succ
;; a → (+ a 1))
(ns literally.hindley.milner
(:require [bodol.parser :as parser]
[bodol.repl :as repl]
[bodol.type.check :as check]))
The hardest problem in computer science:
Naming
Naming
steal some person's name
not somebody still alive
use a CS concept
take popular lang, add "Script"
take letter, increment
pick your favourite pony
Whatever you do, just don't name it after yourself.
GO FORTH
the world needs moar toy lisps