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