summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-05-08 14:02:03 +0000
committerRich Hickey <richhickey@gmail.com>2006-05-08 14:02:03 +0000
commit854ba93bc662517ef4a4bfb683b20bdfc35a2c96 (patch)
tree115d04dec879d524e52fe0fe7089a459b4166c4b
parent62a29c3018a808498bd522518703fc646e404a63 (diff)
added RT cast fns
-rw-r--r--src/org/clojure/runtime/RT.java47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java
index cd9f3677..e68d4d70 100644
--- a/src/org/clojure/runtime/RT.java
+++ b/src/org/clojure/runtime/RT.java
@@ -67,7 +67,7 @@ static public Iter iter(Object coll)
throw new IllegalArgumentException("Don't know how to create Iter from arg");
}
-
+/************************ Boxing/casts *******************************/
static public Object box(Object x)
{
return x;
@@ -113,7 +113,52 @@ static public Double box(double x)
return new Double(x);
}
+static public char charCast(Object x)
+ {
+ if(x instanceof Character)
+ return ((Character)x).charValue();
+ return (char) ((Number)x).intValue();
+ }
+
+static public boolean booleanCast(Object x)
+ {
+ if(x instanceof Boolean)
+ return ((Boolean)x).booleanValue();
+ return x != null;
+ }
+
+static public byte byteCast(Object x)
+ {
+ return ((Number)x).byteValue();
+ }
+
+static public short shortCast(Object x)
+ {
+ return ((Number)x).shortValue();
+ }
+
+static public int intCast(Object x)
+ {
+ return ((Number)x).intValue();
+ }
+
+static public long longCast(Object x)
+ {
+ return ((Number)x).longValue();
+ }
+
+static public float floatCast(Object x)
+ {
+ return ((Number)x).floatValue();
+ }
+
+static public double doubleCast(Object x)
+ {
+ return ((Number)x).doubleValue();
+ }
+
+/******************************************* list support ********************************/
static public Cons cons(Object x, Cons y)
{
return new Cons(x, y);