Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
(defne assoco [m k v o]
([[] _ _ [[k v]]])
([[[k v] . _] _ _ m])
([[[k ?v] . ?r] _ _ [[k v] . ?r]]
(!= m o))
([[[?j v]] _ _ [[?j v] [k v]]]
(!= ?j k))
([[[?j ?u] . ?r] _ _ [[?j ?u] . ?o]]
(!= ?j k)
(!= m o)
;; (match [x y z]
;; [_ f# t#] 1
;; [f# t# _ ] 2
;; [_ _ f#] 3
;; [_ _ t#] 4)
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1)
(pattern-row [(pattern false) (pattern true) wildcard] :a2)
(pattern-row [wildcard wildcard (pattern false)] :a3)
(pattern-row [wildcard wildcard (pattern true)] :a4)]
@swannodette
swannodette / gist:1074818
Created July 10, 2011 18:38
change.clj
(def denoms [2000 1000 500 100 25 10 5 1])
(defn make-change
([amt] (make-change amt denoms {}))
([amt denoms r]
(if (zero? amt)
r
(let [[f :as denoms] (drop-while #(> % amt) denoms)
[n amt] ((juxt quot rem) amt f)]
(recur amt denoms (assoc-in r [f] n))))))
@swannodette
swannodette / gist:997140
Created May 28, 2011 19:26
type-inf.clj
(ns logic.y
(:refer-clojure :exclude [== reify inc])
(:use [clojure.core.logic minikanren prelude
nonrel match]))
(defna findo [x l o]
([_ [[?y :- o] . _] _]
(project [x ?y] (== (= x ?y) true)))
([_ [_ . ?c] _] (findo x ?c o)))
@swannodette
swannodette / dcg.clj
Created May 18, 2011 21:28 — forked from raek/dcg.clj
Definite Clause Grammars with core.logic (aka Logos) in Clojure http://en.wikipedia.org/wiki/Definite_clause_grammar
(ns dcg
(:refer-clojure :exclude [reify == inc])
(:use (clojure.core.logic minikanren prelude)))
(declare sentence noun-phrase verb-phrase det noun verb)
(defn sentence [s1 s3]
(exist [s2]
(noun-phrase s1 s2)
(verb-phrase s2 s3)))
(ns fj
(:import [java.util.concurrent RecursiveTask
ForkJoinPool]))
(set! *warn-on-reflection* true)
;; -----------------------------------------------
;; Helpers to provide an idiomatic interface to FJ
(defprotocol IFJTask
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)