Skip to content

Instantly share code, notes, and snippets.

View ckirkendall's full-sized avatar

Creighton Kirkendall ckirkendall

  • Blue Manta Consulting
  • Cincinnati, Ohio
View GitHub Profile
(ns workbench.enlive.predicate
(:require
[clojure.zip :as z]
[workbench.enlive.engine
:refer [compile-step]]
[workbench.enlive.select
:refer [zip-select]]))
;; ## Builtin predicates
;;
@ckirkendall
ckirkendall / Lambda.clj
Last active December 11, 2015 09:48 — forked from bkyrlach/Lambda.scala
(ns lambda-calc.core)
;; THIS MACRO CREATES A LAMBDA THAT IS COMPATABLE WITH LAMBDA AS DEFINED IN
;; LAMBDA CALCULUS -> CURRIED NON-RECURSIVE
(defmacro f* [args & body]
(let [fsym (gensym "fn")
alist (for [n (range 1 (count args))]
(take n args))
curries (map #(do `(~(vec %) (partial ~fsym ~@%))) alist)]
`(fn ~fsym ~@curries (~args ~@body))))
class Monoid a where
append :: a -> a -> a
identity :: a
foldLeft :: [a] -> b -> (b -> a -> b) -> b
foldLeft [] x f = x
foldLeft (h:l) x f = foldLeft l (f x h) f
instance Monoid Int where
class Comparable a where
compareTo :: a -> a -> Int
intCompare :: Int -> Int -> Int
intCompare x y
| x < y = -1
| x > y = 1
| x == y = 0
instance Comparable Int where
@ckirkendall
ckirkendall / co-contr-implicits.scala
Created September 24, 2012 21:30
Showing how implicits can demonstrate contra and co variance with out all the type noise.
package example
class Widget(val description : String)
class CoolWidget extends Widget("cool widget")
class Sprocket(val description : String)
object Sprocket {
@ckirkendall
ckirkendall / A-Objective.txt
Created September 14, 2012 16:40 — forked from bkyrlach/TreeMagic.scala
Adventures in Type Theory: Parametric Polymorphism(Generics) vs Adhoc Polymophism(Type Classes) (Java,Scala,C#,F#,Nemerle,Haskell)
The Objective
This language experiment was designed to show how parametric polymorphism and type classes are
implemented in different languages. The implementation languages where chosen out of personal
preference. I am well aware it's not complete and would love for you to help me with that. If
you don't see your favorite language please add it as a comment. I am also not an expert in all
of these languages but did try to make them as idiomatic as possible. If you believe there is a
better solution please leave a comment with the implementation.
The Code
@ckirkendall
ckirkendall / optimized-create-rep.clj
Created August 15, 2012 17:52
optimization of create-rep
(defn move [direction {:keys x y :as piece}]
(case direction
:down (assoc piece :y (inc y))
:right (assoc piece :x (inc x))
:left (assoc piece :x (dec x))
:up (assoc piece :y (dec y))
piece))
(defn handle-input [k game-state]
@ckirkendall
ckirkendall / cps.clj
Created July 28, 2012 19:59 — forked from fogus/cps.clj
continuation passing transform macro
(defn & [f k]
(fn [& args]
(k (apply f args))))
(defmacro cps [steps]
(if (seq steps)
`(& ~(first steps)
(cps ~(rest steps)))
`identity))
@ckirkendall
ckirkendall / P26.scala
Created July 27, 2012 15:19 — forked from bkyrlach/P26.scala
Permutations of a list...
object P26 extends App {
def combinations[T](n: Int, l: List[T]): List[List[T]] = {
if(l.size < n) {
Nil
} else {
n match {
case 0 => Nil
case 1 => l.map{List(_)}
case _ => combinations(n-1,l.tail).map{ l.head :: _} ::: combinations(n, l.tail)
}
(defn cxy ([s] (cxy s 0 0))
([[c & s] x y]
(cond
(nil? c) ()
(= c \newline) (recur s 0 (inc y))
:else (conj (cxy s (inc x) y) [c x y]))))