This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defne nqueenso [l n] | |
([() _]) ;; queen list empty, s# | |
([[[x y] . t] _] ;; match/destruct head.tail, ignore n | |
(nqueenso t n) | |
(membero x (range n)) | |
(safeo [x y] t))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def subo | |
(fn ([x y r] | |
(conde | |
[(== x 0) (== y 0) (== r 0)] | |
[(== x 0) (== y 1) (== r -1)] | |
[(== x 1) (== y 0) (== r 1)] | |
[(== x 1) (== y 1) (== r 0)])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Datomic example code | |
(use '[datomic.api :only (db q) :as d]) | |
;; ?answer binds a scalar | |
(q '[:find ?answer :in ?answer] | |
42) | |
;; of course you can bind more than one of anything | |
(q '[:find ?last ?first :in ?last ?first] | |
"Doe" "John") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tut.hello | |
(:use [datomic.api :only [db q] :as d])) | |
(defn add-get-user [uri] | |
(d/create-database uri) | |
(let [conn (d/connect uri) | |
dbase (d/db conn)] | |
(d/transact conn [{:db/id #db/id [:db.part/user] | |
:db/doc "Hello World!"}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns logevt-cl | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic]) | |
(:import [java.util UUID])) | |
(defrel id-name ^:index id ^:index name) | |
(defrel id-time ^:index id ^:index time) | |
(defrel id-op ^:index id ^:index op) | |
(defrel id-cat ^:index id ^:index cat) | |
(defrel id-parent-op ^:index id ^:index parent-op) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [id (java.util.UUID/randomUUID)] | |
(emit-timed {:id id :op :add}) | |
(emit-timed {:id id :cat :backend :op :send}) | |
(emit-timed {:id id :cat :backend :op :ack :parent-op :send}) | |
(emit-timed {:id id :cat :backend :op :sub :parent-op :send}) | |
(emit-timed {:id id :cat :distribution :op :contribute}) | |
(emit-timed {:id id :cat :distribution :op :chain-contribute}) | |
(emit-timed {:id id :cat :distribution :op :chain-event :parent-op :contribute}) | |
(emit-timed {:id id :op :done :parent-op :add}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn draw-line! | |
"Draws a line (bresenham algorithm)" | |
[color [c0 r0] [c1 r1] screen] | |
(let [dc (- c1 c0) | |
dr (- r1 r0) | |
derr (Math/abs (/ dr dc))] | |
(loop [err derr | |
r r0 | |
c c0] | |
(when (< c c1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; example from ScalaCheck | |
(ns string-tests | |
(:use clojure.test.generative)) | |
(defspec startsWith | |
(partial map identity) | |
[^string a ^string b] | |
(assert (.startsWith (str a b) a))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Alan Dipert BFC | |
(defn bfc [program] | |
(let [allowed #{\+ \- \< \> \[ \] \.} | |
src (->> program (filter allowed) | |
(interpose \space) (apply str)) | |
fns (zipmap '(- + < > . ?) (repeatedly gensym))] | |
(letfn [(bfc* [s] | |
(if (vector? s) | |
`(while (not (~(fns '?))) ~@(map bfc* s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns monads | |
(:require clojure.set)) | |
(declare ^:dynamic return | |
^:dynamic bind) | |
(defn lift-inc [v] | |
(return (inc v))) | |
(defn m-add [mv n] |