Skip to content

Instantly share code, notes, and snippets.

@scorbiclife
scorbiclife / lambdaforth.js
Last active April 14, 2025 08:15
Conceptually simple forth implementation
const TERMINAL_INPUT_START = 1000;
const USER_CODE_START = 2000;
/** @type {unknown[]} */
const code = [];
code.push(
_return,
push,
quit,
print,
@scorbiclife
scorbiclife / search.py
Last active March 6, 2025 13:01
minimalistic dfs search for cellular automata
from dataclasses import dataclass
from abc import ABC, abstractmethod
"""Perform a depth-first search for patterns in a cellular automaton.
Some jargon specific for this file
State: Possible values for a `Variable`.
Variable: A place where one can assign a `State` to.
Address: An (x, y, phase) tuple that uniquely identifies a `Variable`.
"""
@scorbiclife
scorbiclife / tagged-unions.ts
Created March 6, 2023 11:23
Simple helpers for tagged unions in typescript
// library code for non-generic discriminated unions
export type ReplaceReturnType<F, R> = F extends (...args: infer Args) => any
? (...args: Args) => R
: never;
export type TaggedUnionFactory<TUF, R> = {
[K in keyof TUF]: ReplaceReturnType<TUF[K], R>;
};
// for monomorphic types this just works well
@scorbiclife
scorbiclife / do-notation-with-for-loops.ts
Last active February 21, 2023 09:35
Do Notation with For Loops
// I'm curious about your thoughts on using for loops for do-notation syntax.
// How does `idresultExpr`, `oresultExpr`, and `presultExpr` look?
// The identity monad
// `iterOfValue` is a generator function.
// it itself is a function, but it can return iterable iterators
function* iterOfValue<T>(x: T): Iterable<T> {
yield x;
}