Divyansh Prakash, September 2023
NOTE: Please read the previous post to understand the context of this post.
// calculates factorials of numbers from 1 to 20 | |
const code = | |
["do", | |
["var", "N", 20], | |
["var", "i", 1], | |
["while", ["<=", "i", "N"], | |
["do", | |
["var", "n", "i"], | |
["var", "f", 1], | |
["while", [">", "n", 0], |
const any = (arr, f) => { | |
for (const x of arr) { | |
if (f(x)) | |
return true; | |
} | |
return false; | |
} | |
const KNOWN_PRIMES = [2]; | |
const primes = (n) => { |
function mapping(f) { | |
return function(rf) { | |
return function(acc, x) { | |
return rf(acc, f(x)) | |
} | |
} | |
} | |
function filtering(f) { | |
return function(rf) { |
function getHeight(tree) { | |
return tree === null? 0: tree.height | |
} | |
function newHeight(leftSubtree, rightSubtree) { | |
return Math.max(getHeight(leftSubtree), getHeight(rightSubtree)) + 1 | |
} | |
function insert(tree, e) { | |
if(tree === null) |
(ns sequence | |
(:refer-clojure :exclude [sequence sort]) | |
(:require [clojure.core :as core])) | |
;; Helper | |
;; ====== | |
(defn accumulate | |
([]) | |
([acc] acc) | |
([acc x] (conj (vec acc) x))) |
<!DOCTYPE html> | |
<html lang="en"> | |
<title>Test React</title> | |
<head> | |
<script src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
<script src="https://unpkg.com/[email protected]/babel.min.js"></script> | |
</head> | |
<body> | |
<div id="app"></div> |
const CLOSED = Symbol('chan-closed'); | |
const StackGC = async () => null; | |
class Chan { | |
constructor(size) { | |
this.q = []; | |
this.size = size || 1; | |
this.isClosed = false; | |
} |
// StackGC | |
// ======= | |
const StackGC = async () => null; | |
// Tests | |
// ===== | |
// util | |
function assert(assertion, msg) { | |
console.assert(assertion, `%s`, msg); |
<html> | |
<head> | |
<script type="text/javascript"> | |
// Trampoline | |
// ========== | |
class Thunk { | |
constructor(f) { | |
this.f = f; | |
} | |
} |
Divyansh Prakash, September 2023
NOTE: Please read the previous post to understand the context of this post.