Mercurial > lasercutter
annotate src/clojure/contrib/condition/Condition.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
rev | line source |
---|---|
rlm@10 | 1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and |
rlm@10 | 2 ;; distribution terms for this software are covered by the Eclipse Public |
rlm@10 | 3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can |
rlm@10 | 4 ;; be found in the file epl-v10.html at the root of this distribution. By |
rlm@10 | 5 ;; using this software in any fashion, you are agreeing to be bound by the |
rlm@10 | 6 ;; terms of this license. You must not remove this notice, or any other, |
rlm@10 | 7 ;; from this software. |
rlm@10 | 8 ;; |
rlm@10 | 9 ;; Condition.clj |
rlm@10 | 10 ;; |
rlm@10 | 11 ;; Used by clojure.contrib.condition to implement a "Throwable map" |
rlm@10 | 12 ;; |
rlm@10 | 13 ;; scgilardi (gmail) |
rlm@10 | 14 ;; Created 09 June 2009 |
rlm@10 | 15 |
rlm@10 | 16 (ns clojure.contrib.condition.Condition |
rlm@10 | 17 (:gen-class :extends Throwable |
rlm@10 | 18 :implements [clojure.lang.IMeta] |
rlm@10 | 19 :state state |
rlm@10 | 20 :init init |
rlm@10 | 21 :post-init post-init |
rlm@10 | 22 :constructors {[clojure.lang.IPersistentMap] |
rlm@10 | 23 [String Throwable]})) |
rlm@10 | 24 |
rlm@10 | 25 (defn -init |
rlm@10 | 26 "Constructs a Condition object with condition (a map) as its |
rlm@10 | 27 metadata. Also initializes the superclass with the values at :message |
rlm@10 | 28 and :cause, if any, so they are also available via .getMessage and |
rlm@10 | 29 .getCause." |
rlm@10 | 30 [condition] |
rlm@10 | 31 [[(:message condition) (:cause condition)] (atom condition)]) |
rlm@10 | 32 |
rlm@10 | 33 (defn -post-init |
rlm@10 | 34 "Adds :stack-trace to the condition. Drops the bottom 3 frames because |
rlm@10 | 35 they are always the same: implementation details of Condition and raise." |
rlm@10 | 36 [this condition] |
rlm@10 | 37 (swap! (.state this) assoc |
rlm@10 | 38 :stack-trace (into-array (drop 3 (.getStackTrace this))))) |
rlm@10 | 39 |
rlm@10 | 40 (defn -meta |
rlm@10 | 41 "Returns this object's metadata, the condition" |
rlm@10 | 42 [this] |
rlm@10 | 43 @(.state this)) |