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 / gitget.py
Last active July 10, 2021 22:45
Download a specific folder from a github repo
#!/usr/bin/python
"""
Download a specific folder from a github repo:
gitget.py https://github.com/divs1210/kilvish/tree/master/examples/bricksnball
"""
__author__ = 'Divyansh Prakash'
import sys
import subprocess
@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]
(ns maya)
(defmacro math->
" (math-> 1 + 5 * 2 / 3) ;=> (-> 1 (+ 5) (* 2) (/ 3)) ;=> 4 "
[exp & f-x-pairs]
(if (even? (count f-x-pairs))
`(-> ~exp
~@(for [[f x] (partition 2 f-x-pairs)]
(list f x)))
(throw (Exception. "f-x-pairs should be even."))))
@divs1210
divs1210 / calculus.clj
Last active August 1, 2020 11:01
Calculus in Clojure
(ns calculus)
(defonce ^:const dx 0.00001M)
(defn df
"Returns the derivative of f."
[f]
(fn [x]
(/ (- (f (+ x dx)) (f x))
dx)))
@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