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
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous. | |
;; This defines the event stream, in this case just a series of numbers, | |
;; a new one produced each second | |
(defn timer [] | |
(lazy-seq | |
(do | |
(Thread/sleep 1000) | |
(cons (System/nanoTime) (timer))))) |
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 safeo | |
"Is the queen q safe from all queens in list" | |
[q others] | |
([_ ()]) | |
([[x1 y1] [[x2 y2] . t]] | |
(!= x1 x2) | |
(!= y1 y2) | |
(project [x1 x2 y1 y2] | |
(!= (- x2 x1) (- y2 y1)) | |
(!= (- x1 y2) (- x2 y1))) |
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 sort-parts | |
"Lazy, tail-recursive, incremental quicksort. Works against | |
and creates partitions based on the pivot, defined as 'work'." | |
[work] | |
(lazy-seq | |
(loop [[part & parts] work] | |
(if-let [[pivot & xs] (seq part)] | |
(let [smaller? #(< % pivot)] | |
(recur (list* | |
(filter smaller? xs) |
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 jdbc.core | |
(:require [clojure.java.jdbc :as jdbc])) | |
(def db-spec {:classname "org.sqlite.JDBC" | |
:subprotocol "sqlite" | |
:subname "test.db"}) | |
(jdbc/with-connection db-spec | |
(jdbc/create-table :authors | |
[:id "integer primary key"] |
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 join-test3 [xs ys] | |
(let [db-base (make-database | |
(relation :last-first-email [:last :first :email]) | |
(index :last-first-email :email) | |
(relation :email-height [:email :height]) | |
(index :email-height :email)) | |
rules (rules-set | |
(<- (:first-height :first ?f :height ?h) | |
(:last-first-email :last ?l :first ?f :email ?e) | |
(:email-height :email ?e :height ?h))) |
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 metaballs | |
(:import | |
[javax.swing JFrame] | |
[java.awt Canvas Graphics Color] | |
java.awt.image.BufferStrategy)) | |
(set! *warn-on-reflection* true) | |
(def ^:const SIZE 250) | |
(defn direction [p v] |
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
(require 'leiningen.core.project)(leiningen.core.project/defproject _"":dependencies[[leiningen-core"2.0.0-preview8"]]:plugins[[lein-swank"1.4.4"]]:main project :source-paths["."])(ns project)(defn -main[](let[f(doto(java.awt.Frame.)(.setUndecorated true))](->(java.awt.GraphicsEnvironment/getLocalGraphicsEnvironment).getDefaultScreenDevice(.setFullScreenWindow f))(.createBufferStrategy f 2)(let[b(.getBufferStrategy f)s(.getBounds f)](while 1(let[g(.getDrawGraphics b)](try(.setColor g(java.awt.Color.(rand-int 0xffffff)))(.fillRect g 0 0(.width s)(.height s))(finally(.dispose g))))(when-not(.contentsLost b)(.show b))(Thread/sleep 20))))) |
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
;; http://www.infoq.com/presentations/core-logic | |
(ns rdf | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic])) | |
(def g | |
[[:a1 :rdf/type :sdx/FederationService] | |
[:a1 :rdf/type :sdx/name "movies"] | |
[:a1 :rdf/exposedServices :_syscoll1] |
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
;; http://dosync.posterous.com/know-your-bounds | |
(defrel connected ^:index x ^:index y) | |
(facts connected [[1 2] [1 5]]) | |
(facts connected [[2 1] [2 3] [2 5]]) | |
(facts connected [[3 2] [3 4]]) | |
(facts connected [[4 3] [4 5] [4 6]]) | |
(facts connected [[5 1] [5 2] [5 4]]) | |
(facts connected [[6 4]]) |
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 diago [qi qj d rng] | |
(fresh [qid qjd] | |
(infd qid qjd rng) | |
(+fd qi d qid) | |
(!=fd qid qj) | |
(+fd qj d qjd) | |
(!=fd qjd qi))) | |
(defn diagonalso [n r] | |
((fn dloop [r i s j] |