Skip to content

Instantly share code, notes, and snippets.

View aboekhoff's full-sized avatar

Andrew Boekhoff aboekhoff

  • DemandingBear
  • San Francisco
View GitHub Profile
(defmonad
:name :parser
:do parsing
:bind (fn [mv f]
(fn [s]
(when-let [[v s*] (mv s)]
((f v) s*))))
:return (fn [v] (fn [s] [v s]))
:zero (fn [s] nil)
:plus (fn [a b] (fn [s] (or (a s) (b s))))
;;;; this cps style code
(anf-name x (fn [a]
(anf y (fn [b]
(anf z (fn [c]
(k [:if a b c])))
;;;; becomes
(run-cps
(ns parenja.reader
(:refer-clojure :rename {list clj-list
symbol clj-symbol
keyword clj-keyword
vector clj-vector}
:exclude [unquote unquote-splicing read])
(:use somnium.yap
combinatrix.parser
combinatrix.parser.text
[combinatrix.util :only [definitions]]))
(ns poet.prelude)
(def prelude
'[(syntax-rule if ()
(_ X Y Z) (if* (op* === X true) Y
(if* (op* === X false) Z
(throw "if requires a boolean value"))))
(syntax-rule if-not ()
(_ X Y Z) (if X Z Y))
space_283 = (function (ST_729) {
var rtn734_, v_440_;
v_440_ = re_267("\\s");
rtn734_ = v_440_(ST_729);
return rtn734_;
});
spaces_284 = (function (ST_730) {
var v_441_, rtn735_;
v_441_ = many_261(space_283);
rtn735_ = v_441_(ST_730);
;;;; pairs
(define-type Pair a b)
(define-type Empty)
(define Pair:foldl
f x (Pair a b) -> (foldl f (f x a) b))
(define Pair:first
(Pair a _) -> (Some a))
;;;; red-black-trees, based on the Functional Pearls article:
;;;; 'Red-Black Trees in a Functional Setting' by Chris Okasaki, 1993
(define-type R | B) ;; red black
(define-type T color left elt right) ;; tree
(define rbt:insert
x t -> (match (rbt:insert* x t)
(T _ a y b) -> (T B a y b)))
;;;; structural types + pattern matching in Clojure
;;;; with the obligatory unbalanced binary tree example
(define-struct leaf value)
(define-struct node left elt right)
(define insert
nil x -> (leaf x)
(leaf a) x -> (cond (or (nil? a) (= a x)) (leaf a)
(< x a) (node (leaf x) a nil)
;; SFML/System.h
;; ////////////////////////////////////////////////////////////
;; #ifndef SFML_SYSTEM_H
;; #define SFML_SYSTEM_H
;; ////////////////////////////////////////////////////////////
;; // Headers
;; ////////////////////////////////////////////////////////////
const h1 = {
a: {
b: {
c: {
foo: "bar"
}
}
}
}