This file contains hidden or 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
--- src/clj/cljs/analyzer.clj 2012-11-17 01:01:55.712323358 -0500 | |
+++ src/cljs/cljs/analyzer.cljs 2012-11-17 11:51:47.030558150 -0500 | |
@@ -6,14 +6,23 @@ | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
-(set! *warn-on-reflection* true) | |
+;; (set! *warn-on-reflection* true) | |
(ns cljs.analyzer |
This file contains hidden or 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 all-distinctfd [l] | |
([()]) | |
([[h . t]] | |
(distinctfd h) | |
(all-distinctfd t))) | |
(run 1 [q] | |
(fresh [a1 a2 a3 a4 | |
b1 b2 b3 b4 | |
c1 c2 c3 c4 |
This file contains hidden or 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 queries | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic]) | |
(:use [datomic.api :only [q]])) | |
(defn query [rule xs] | |
(let [prule (prep rule)] | |
(map #(binding-map* prule (prep %)) xs))) | |
;; --- |
This file contains hidden or 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 | |
;; Demonstrates using datalog with Clojure defrecords | |
(use '[datomic.api :only [q db] :as d]) | |
;;; http://www.lshift.net/blog/2010/08/21/some-relational-algebra-with-datatypes-in-clojure-12 | |
(defrecord Supplier [number name status city]) | |
(defrecord Part [number name colour weight city]) | |
(defrecord Shipment [supplier part quantity]) | |
;; sample data |
This file contains hidden or 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
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains hidden or 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
(use '[datomic.api :only [q db] :as d]) | |
(def uri "datomic:mem://accounts") | |
;; create database | |
(d/create-database uri) | |
;; connect to database | |
(def conn (d/connect uri)) |
This file contains hidden or 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
(use 'clojure.core.logic | |
'clojure.core.logic.arithmetic) | |
(defne diffo | |
[l] | |
([[]]) | |
([[x]]) | |
([[x y . tail]] | |
(fresh [l0 l1] | |
(!= x y) |
This file contains hidden or 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 commatize [n] | |
(if (nil? n) | |
"" | |
(let [s (str n)] | |
(apply str | |
(reverse (drop-last | |
(interleave | |
(reverse s) | |
(take (count s) (flatten (repeat [nil nil \,])))))))))) |
This file contains hidden or 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 challenge.weights | |
(:require [clojure.contrib.combinatorics :as c])) | |
(defn weigh? [i l r] | |
(let [l-weight (apply + i l)] | |
(some #(when (= l-weight (apply + %)) [l %]) (set (c/subsets r))))) | |
(defn diff [l1 l2] | |
(reduce (fn [l i] | |
(let [[b [f & r]] (split-with (complement #{i}) l)] |
This file contains hidden or 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
(define (subchecko w sl r o n) | |
(conde | |
((== sl ()) | |
(fresh (a d) | |
(domfd a (range 1 n)) | |
(conde | |
((conso a d r) (plusfd a 1 w) | |
(conso w r o)) | |
((== r '()) (conso w r o))))) | |
((fresh (a b c ro0 ro1 nw nsl) |