Skip to content

Instantly share code, notes, and snippets.

@Glorp
Glorp / lambda
Last active October 12, 2015 12:27
Lambdas
0 := λf.λx.x
1 := λf.λx.f x
2 := λf.λx.f (f x)
succ := λn.λf.λx.f (n f x)
+ := λa.λb.a succ b
* := λa.λb.a (b succ) 0
pair := λa.λb.λf.f a b
fst := λc.c (λa.λb.a)
@Glorp
Glorp / husdyr.rkt
Last active December 13, 2015 18:38
#lang racket
(require "mk.rkt")
(define (conso a d c)
(== `(,a . ,d) c))
(define (caro c a)
(fresh (d)
(conso a d c)))
@Glorp
Glorp / typing.rkt
Last active December 17, 2015 11:29
#lang racket
(require "mk.rkt")
;; mostly https://gist.github.com/swannodette/997140
;; probably sprinkled with broken
(define (findo x l o)
(fresh (s v d)
(symbolo x)
(== `((,s : ,v) . ,d) l)
@Glorp
Glorp / racktors.rkt
Last active December 23, 2015 11:39
#lang racket
(require racket/async-channel)
(provide spawn ! ? self)
;; kind of actors built from channels and parameters
;; which is not to say that that is a good idea
(define self-param (make-parameter #f))
(define (self) (or (self-param) (error)))
@Glorp
Glorp / monads.rkt
Last active December 23, 2015 22:49
#lang racket
(struct functor (fmap))
(struct monad functor (unit bind then))
(define (make-monad unit bind (then #f))
(monad (λ (f m) (bind m (λ (x) (unit (f x)))))
unit
bind
@Glorp
Glorp / ant.rkt
Last active December 28, 2015 12:29
#lang racket
(require (except-in 2htdp/universe left right)
2htdp/image)
(struct pos (x y) #:transparent)
(struct ant (pos dir) #:transparent)
(struct world (a b n) #:transparent)
(define dirs
(let* ([i (overlay (triangle 8 "solid" "black")
datatype nat = z | s of nat
fun fold _ zv z = zv
| fold sf zv (s n) = sf (fold sf zv n)
fun pz _ = z
fun ps g h = h (g s)
fun id x = x
fun p n = (fold ps pz n) id
@Glorp
Glorp / test.rkt
Last active January 1, 2016 11:39
xmaslang
#lang reader "xmaslang.rkt"
-+
+/|+5++3 1 1 <x +2x>
$->#2<x 1>s 1<i+s i>
+||#5<x ->x<y+$x z 100 <k - z k
>y> > <x $x a 0 <b +a b> > | -
$ ->#10<x#x>x0<y+x$y z0<y+y z>>
$ ->->#30<x+x1> <x%
$->#10<a*a$=?->#<foo?=foo*2
4<bar*+foo bar bar>[-20 15]
#lang racket
(require 2htdp/image)
(define-syntax structs
(syntax-rules ()
[(_) (begin)]
[(_ (name args ...) rest ...) (begin (struct name (args ...) #:transparent)
(structs rest ...))]))
(structs
#lang racket
(provide (rename-out (module-begin #%module-begin))
#%app)
(define (push stack x)
(cons x stack))
(define (add stack)
(match stack
[(list b a xs ...) (cons (+ a b) xs)]))