diff options
-rw-r--r-- | src/org/clojure/runtime/Keyword.java | 43 | ||||
-rw-r--r-- | src/org/clojure/runtime/Symbol.java | 6 |
2 files changed, 46 insertions, 3 deletions
diff --git a/src/org/clojure/runtime/Keyword.java b/src/org/clojure/runtime/Keyword.java new file mode 100644 index 00000000..47dc6cbb --- /dev/null +++ b/src/org/clojure/runtime/Keyword.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Mar 29, 2006 10:39:05 AM */ + +package org.clojure.runtime; + +public class Keyword extends Symbol{ +/** + * Used by Namespace.intern() + * + * @param name + * @param ns + */ +Keyword(String name, Namespace ns) + { + super(name, ns); + this.val = this; + this.fn = this; + } + +public Object getValue(ThreadLocalData tld) + { + return this; + } + +public Object setValue(ThreadLocalData tld, Object val) + { + throw new UnsupportedOperationException("Cannot set the value of a keyword"); + } + +public String toString() + { + return ":" + name; + } +} diff --git a/src/org/clojure/runtime/Symbol.java b/src/org/clojure/runtime/Symbol.java index 4361c24b..497e138b 100644 --- a/src/org/clojure/runtime/Symbol.java +++ b/src/org/clojure/runtime/Symbol.java @@ -17,7 +17,7 @@ public class Symbol extends AFn{ public final static Object UNBOUND = new Object(); public final String name; -public final Namespace namespace; +public Namespace namespace; public Object val = UNBOUND; public IFn fn; //todo, bind to throw stub? @@ -33,13 +33,13 @@ Symbol(String name, Namespace ns) this.name = name; } -public Object getValue(ThreadLocalData tld) throws Exception +public Object getValue(ThreadLocalData tld) { Cons binding = tld.getDynamicBinding(this); if(binding != null) return binding.first; if(val == UNBOUND) - throw new Exception(name + " is unbound."); + throw new IllegalStateException(name + " is unbound."); return val; } |