Skip to content

Instantly share code, notes, and snippets.

Avatar
😸
Pondering language design...

serialhex

😸
Pondering language design...
View GitHub Profile
@nicebyte
nicebyte / dyn_arr.h
Last active April 6, 2023 16:48
dyn_arr
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
; A MICRO-MANUAL FOR LISP - NOT THE WHOLE TRUTH, 1978
; John McCarthy, Artificial Intelligence Laboratory, Stanford University
; https://www.ee.ryerson.ca/~elf/pub/misc/micromanualLISP.pdf
; https://github.com/jaseemabid/micromanual
; for CL : Rainer Joswig, joswig@lisp.de
; this version runs in a Common Lisp
@privet-kitty
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
zmactep / encodings.md
Created August 20, 2017 13:08
Number encodings
View encodings.md

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
mujahidk / ls-mega-bytes.sh
Created December 23, 2016 15:01
List files using ls and size in MB (mega bytes)
View ls-mega-bytes.sh
# https://xkcd.com/1168/ :)
ls -l --block-size=M
@zehnpaard
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
(require
[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
andymatuschak / States-v3.md
Last active April 26, 2023 04:56
A composable pattern for pure state machines with effects (draft v3)
View States-v3.md

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
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active May 9, 2023 17:39
Reader Macros in Common Lisp
View _reader-macros.md

Reader Macros in Common Lisp

This post also appears on lisper.in.

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. ...read-macros... do their work at read-time.