Skip to content

Instantly share code, notes, and snippets.

View serialhex's full-sized avatar
Pondering language design...


Pondering language design...
View GitHub Profile
nicebyte / dyn_arr.h
Last active January 23, 2024 00:10
#pragma once
#define DYN_ARR_OF(type) struct { \
type *data; \
type *endptr; \
uint32_t capacity; \
#if !defined(__cplusplus)
#define decltype(x) void*
; John McCarthy, Artificial Intelligence Laboratory, Stanford University
; for CL : Rainer Joswig,
; this version runs in a Common Lisp
privet-kitty / map-literal.lisp
Last active March 2, 2023 20:46
Clojure's {} in Common Lisp
;; {}: Map literal like Clojure
;; Note:
;; 1. Equality operator is #'eql.
;; 2. {} is a literal here though it is a constructor in Clojure:
;; Clojure:
;; (:b {:a 1 :b (+ 1 2)}) => 3
;; CL:
;; (gethash :b {:a 1 :b (+ 1 2)}) => (+ 1 2)
zmactep /
Created August 20, 2017 13:08
Number encodings

Alternative to the Church, Scott and Parigot encodings of data on the Lambda Calculus.

When it comes to encoding data on the pure λ-calculus (without complex extensions such as ADTs), there are 3 widely used approaches.

Church Encoding

The Church Encoding, which represents data structures as their folds. Using Caramel’s syntax, the natural number 3 is, for example. represented as:

0 c0 = (f x -> x)
1 c1 = (f x -> (f x))
2 c2 = (f x -> (f (f x)))
seanjensengrey / tiny.c
Last active March 25, 2024 16:46
Marc Feeley Tiny C compiler
/* file: "tinyc.c" */
/* originally from */
/* Copyright (C) 2001 by Marc Feeley, All Rights Reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
mujahidk /
Created December 23, 2016 15:01
List files using ls and size in MB (mega bytes)
# :)
ls -l --block-size=M
zehnpaard / simple-compojure.core.clj
Created October 30, 2016 06:03
Simple Compojure Demo with GET/POST forms
(ns simple-compojure.core
[ring.adapter.jetty :refer [run-jetty]]
[ring.middleware.params :as p]
[simple-compojure.middleware :as m]
[simple-compojure.routes :as r]
(def app
(-> r/routes
andymatuschak /
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

# Hello, and welcome to makefile basics.
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
# Once you're done here, go to
# to learn SOOOO much more.