Skip to content

Instantly share code, notes, and snippets.

Pondering language design...


Pondering language design...
View GitHub Profile
nicebyte / dyn_arr.h
Last active April 6, 2023 16:48
View dyn_arr.h
#pragma once
#define DYN_ARR_OF(type) struct { \
type *data; \
type *endptr; \
uint32_t capacity; \
#if !defined(__cplusplus)
#define decltype(x) void*
View mccarthy-eval.lisp
; 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
View map-literal.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)))
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
View simple-compojure.core.clj
(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 April 26, 2023 04:56
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,

View Makefile
# 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.
chaitanyagupta /
Last active May 9, 2023 17:39
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. do their work at read-time.