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
# A priority queue-based, wheel-using incremental Sieve of Eratosthenes. | |
# See `The Genuine Sieve of Eratosthenes' by Melissa E. O'Neill | |
# (http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf) | |
# for the Haskell incremental sieve which inspired this implementation | |
# (along with detailed analyses of performance of several Haskell | |
# sieves). | |
# | |
# Usage: | |
# Sieve() -> simple SoE | |
# Sieve(Wheel(4)) -> SoE + a wheel based on 4 initial primes |
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 transient-incremental-sieve [] | |
(map first | |
(iterate (fn [[previous crossouts]] | |
(loop [current (inc previous) | |
crossouts (transient crossouts)] | |
(if-let [witnesses (crossouts current)] | |
(recur (inc current) | |
(dissoc! (loop [cs crossouts | |
ws witnesses] | |
(if-let [w (first ws)] |
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
(declare leftist-heap) | |
(defprotocol heap | |
(heap-empty? [h]) | |
(heap-merge [h1 h2]) | |
(heap-rank [h]) | |
(heap-insert [h x]) | |
(heap-get-min [h]) | |
(heap-del-min [h])) |
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
(defmacro scond | |
"Scheme style cond macro. | |
Use :>> instead of => and :else instead of else." | |
[& clauses] | |
(when-let [clause (first clauses)] | |
(cond | |
(= (first clause) :else) (if (next clauses) | |
(throw (IllegalArgumentException. | |
(str ":else clause must be last in scond: " |
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
(setq clojure-project-extra-classpaths | |
'( | |
; "deps/" | |
"src/" | |
"classes/" | |
"test/" | |
)) | |
(setq clojure-project-jar-classpaths | |
'( |
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.contrib.seq :only (reductions)]) | |
;;; Calculate π through Euler-van Wijngaarden transformation of Gregory-Leibniz series | |
(def *use-exact-numbers* true) | |
(defn gregory-leibniz-series [] | |
(map #(/ 4 %) | |
(interleave (iterate #(+ % 4) (if *use-exact-numbers* 1 1.)) | |
(iterate #(- % 4) (if *use-exact-numbers* -3 -3.))))) |
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
;;; all code in this function lifted from the clojure-mode function | |
;;; from clojure-mode.el | |
(defun clojure-font-lock-setup () | |
(interactive) | |
(set (make-local-variable 'lisp-indent-function) | |
'clojure-indent-function) | |
(set (make-local-variable 'lisp-doc-string-elt-property) | |
'clojure-doc-string-elt) | |
(set (make-local-variable 'font-lock-multiline) t) |
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 | |
#^{:doc "CL original by Peter Norvig, initial version in Clojure by Kevin Livingston. See http://groups.google.com/group/clojure/browse_thread/thread/996ecadf98328c6b#"} | |
unifier.core | |
(:use [clojure.contrib.def :only (defvar)])) | |
(defn variable? | |
"Is x a variable (a symbol beginning with '?')?" | |
[x] | |
(and (symbol? x) (= (first (name x)) \?))) |
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 | |
#^{:doc "CL original by Peter Norvig, initial version in Clojure by Kevin Livingston. See http://groups.google.com/group/clojure/browse_thread/thread/996ecadf98328c6b#"} | |
unifier.core | |
(:use [clojure.contrib | |
[def :only (defvar defalias)] | |
[core :only (seqable?)]]) | |
(:require [clojure | |
[walk :as walk] | |
[zip :as zip]])) |
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
(defmacro update-bean | |
[obj props-map] | |
`(let [obj# ~obj | |
props-map# ~props-map | |
dots# (map (fn [[k# v#]] | |
`(. ~(->> k# as-str camelize upcase (str "set") symbol) ~v#)) | |
props-map#) | |
doto# `(doto ~obj# ~@dots#)] | |
(eval doto#))) |
OlderNewer