Skip to content

Instantly share code, notes, and snippets.

@divs1210
divs1210 / cek.py
Last active June 21, 2020 17:24 — forked from cheery/cek.py
CEK abstract machine
class Var(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
class Lam(object):
def __init__(self, bind, expr):
self.bind = bind
@divs1210
divs1210 / futamura.md
Last active May 2, 2020 01:23
Futamura Projections Demo in Clojure

Futamura Projections

Insight

Name Type
Inputs Any
Output Any
Program Text
Compiler Program => CompiledProgram
@divs1210
divs1210 / futamura.clj
Last active May 1, 2020 23:01
Futamura Projections in Clojure
(ns futamura
(:require [clojure.string :as str]))
;; ========= util =====================
(defn get-source-code [var]
(let [{:keys [file line]} (meta var)
file (slurp file)
lines (->> file
str/split-lines
(drop (dec line)))
@divs1210
divs1210 / fsm.clj
Last active April 30, 2020 05:11
Simple, fast fsm for all your needs
;; Implementation
;; ==============
(defn- return
[base stack]
(reduce (fn [acc f]
(f acc))
base
stack))
(defn run-fsm
(ns pascal)
(defn step [row]
(let [parents (partition 2 1 row)
new-row-middle (map (fn [[x y]]
(+ x y))
parents)]
(concat [1] new-row-middle [1])))
(defonce pascals-triangle
def ordered_infix(*nums_and_ops)
initial_val = nums_and_ops[0]
op_num_pairs = nums_and_ops.drop(1).each_slice(2).to_a
op_num_pairs.reduce(initial_val) do |accumulator, op_num_pair|
op, num = op_num_pair
accumulator.send(op, num)
end
end
ordered_infix 10, '/', 2, '-', 1, '*', 2
@divs1210
divs1210 / watch_db.cljs
Created December 14, 2018 11:26
Lightweight logging of db state changes for reagent/re-frame
(defn watch-db []
(add-watch re-frame.db/app-db :watcher
(fn [_ _ old-state new-state]
(let [[removed added] (clojure.data/diff old-state new-state)]
(when (or removed added)
(println "=====\nRemoved:")
(cljs.pprint/pprint removed)
(println "Added:")
(cljs.pprint/pprint added))))))
@divs1210
divs1210 / data.edn
Created November 24, 2018 15:33
sample edn data
{:result 1}
@divs1210
divs1210 / go-for-js-geeks.json
Created November 22, 2018 16:45
Go for JS Geeks
{"result": 5}