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
;; demonstrating structural sharing | |
;; in clojure.lang.PersistentVector | |
;; instances | |
(let [v1 (vec (range 100)) | |
v2 (conj v1 :foo) | |
v3 (conj v1 :bar) | |
v4 (conj (vec (range 100)) :quux) | |
PV-root (doto (.getDeclaredField clojure.lang.PersistentVector "root") | |
(.setAccessible true)) |
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
(deftype Foo [x y z] | |
clojure.lang.IKeywordLookup | |
(getLookupThunk | |
[self k] | |
(reify | |
clojure.lang.ILookupThunk | |
(get | |
[self k] | |
(if-let [v (k {:x x :y y :z z})] | |
(inc v))))) |
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#))) |
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
(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
;;; 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
(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
(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
(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
(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])) |