Skip to content

Instantly share code, notes, and snippets.

@divs1210
divs1210 / lisp.html
Last active August 12, 2021 21:55
Simple lisp interpreter in browser
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<center>
<h3>Lisp.js</h3>
@divs1210
divs1210 / Solver.md
Last active July 16, 2021 20:30
Arithmetic solver

Code

(import (rnrs))

(define (derive f dx)
  (lambda (x)
    (/ (- (f (+ x dx))
          (f x))
       dx)))
@divs1210
divs1210 / transducers.clj
Last active June 27, 2021 14:05
Learn Clojure transducers by implementing them!
(ns transducers
"Learn transducers by implementing them."
(:refer-clojure :exclude [map filter transduce sequence]))
(comment
"Let's forget, for the sake of this experiment, about laziness in Clojure.
We can implement eager versions of Clojure's `map` and `filter` functions as follows:")
(defn map
[f coll]
@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