Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 2524efd9e9d6bd32b7a01934ed631f00fe86e705 0 parents
Swarm Coders authored
10 .gitignore
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
13 README.md
@@ -0,0 +1,13 @@
+# metaverse
+
+A Clojure library designed to ... well, that part is up to you.
+
+## Usage
+
+FIXME
+
+## License
+
+Copyright © 2012 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
3  doc/intro.md
@@ -0,0 +1,3 @@
+# Introduction to metaverse
+
+TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
7 project.clj
@@ -0,0 +1,7 @@
+(defproject metaverse "0.1.0-SNAPSHOT"
+ :description "FIXME: write description"
+ :url "http://example.com/FIXME"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[org.clojure/clojure "1.4.0"]]
+ :profiles {:dev {:source-paths ["sample-src" "sample-src2"]}})
7 sample-src/sample/a.clj
@@ -0,0 +1,7 @@
+(ns sample.a)
+
+(defn abc []
+ :original)
+
+(defn efg []
+ :original)
7 sample-src2/sample/a.clj
@@ -0,0 +1,7 @@
+(ns sample.a)
+
+(defn abc []
+ :alternate)
+
+(defn efg []
+ :alternate)
56 src/meta/verse.clj
@@ -0,0 +1,56 @@
+;; (ns clojure.core)
+
+;; (defn versioned-lib [lib rev]
+;; (if (or (nil? rev) (= :head rev))
+;; lib
+;; ))
+
+;; (defn- versioned-require [[lib & {:as opts}]]
+;; (load (root-resource (versioned-lib lib (:rev opts)))))
+
+;; (defn- ns-clause [clauses])
+
+;; (defmacro ns- [name & clauses]
+;; `(ns ~name
+;; ~@(map ns-clause clauses)))
+
+(ns meta.verse
+ (:refer-clojure :exclude [load require])
+ (:require [clojure.java.io :as io]
+ [clojure.pprint :as pp])
+ (:import (java.security MessageDigest)
+ (clojure.lang LineNumberingPushbackReader)))
+
+(defn sha1 [bytes]
+ (let [digest (.digest (MessageDigest/getInstance "SHA1") bytes)]
+ (format "%x" (BigInteger. 1 digest))))
+
+(defonce ccl (.getContextClassLoader (Thread/currentThread)))
+
+(defn transform [ns-form checksum]
+ (let [transformed-ns (symbol (str (second ns-form) "." checksum))]
+ `(ns ~transformed-ns ~@(drop 2 ns-form))))
+
+(defn read-all [resource]
+ (let [reader (LineNumberingPushbackReader. (io/reader resource))
+ forms (repeatedly #(read reader false ::eof))]
+ (take-while #(not= ::eof %) forms)))
+
+(defn transformed-sources [lib]
+ (let [matches (enumeration-seq (.findResources ccl lib))]
+ (for [match matches
+ :let [checksum (sha1 (.getBytes (slurp match)))
+ [ns-form & body] (read-all match) ]]
+ (cons (transform ns-form checksum) body))))
+
+(defn load [lib]
+ ;; (clojure.core/load lib)
+ (doseq [transformed (transformed-sources lib)]
+ (binding [*ns* (find-ns 'user)]
+ (doseq [form transformed]
+ (eval form)))))
+
+(defn pprint [lib]
+ (doseq [transformed (transformed-sources lib)]
+ (pp/pprint transformed)))
+
7 test/metaverse/core_test.clj
@@ -0,0 +1,7 @@
+(ns metaverse.core-test
+ (:use clojure.test
+ metaverse.core))
+
+(deftest a-test
+ (testing "FIXME, I fail."
+ (is (= 0 1))))
Please sign in to comment.
Something went wrong with that request. Please try again.