summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-09-19 15:45:43 +0000
committerRich Hickey <richhickey@gmail.com>2007-09-19 15:45:43 +0000
commit8882ed0d74714d58dac777ec7383beab184fb38a (patch)
treefd47b4e8935ca10299b410af439c97703db8ea6a /src
parentc13e11f2fec745192c2364e9e60d4d387c365cda (diff)
fixed pop and metadata semantics
Diffstat (limited to 'src')
-rw-r--r--src/jvm/clojure/lang/PersistentList.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/jvm/clojure/lang/PersistentList.java b/src/jvm/clojure/lang/PersistentList.java
index c7331ef5..f1130195 100644
--- a/src/jvm/clojure/lang/PersistentList.java
+++ b/src/jvm/clojure/lang/PersistentList.java
@@ -28,13 +28,6 @@ public PersistentList(Object first){
this._count = 1;
}
-PersistentList(Object first, PersistentList rest){
- this._first = first;
- this._rest = rest;
-
- this._count = 1 + rest.count();
-}
-
PersistentList(IPersistentMap meta, Object _first, PersistentList _rest, int _count){
super(meta);
this._first = _first;
@@ -59,12 +52,18 @@ public ISeq rest(){
return _rest;
}
+public IPersistentList pop(){
+ if(_rest == null)
+ return EMPTY.withMeta(meta());
+ return _rest;
+}
+
public int count(){
return _count;
}
public ISeq cons(Object o){
- return new PersistentList(o, this);
+ return new PersistentList(meta(), o, this, _count + 1);
}
public PersistentList withMeta(IPersistentMap meta){
@@ -78,7 +77,7 @@ static class EmptyList extends PersistentList{
}
public ISeq cons(Object o){
- return new PersistentList(o, null);
+ return new PersistentList(meta(), o, null, 1);
}
public PersistentList withMeta(IPersistentMap meta){
@@ -87,6 +86,10 @@ static class EmptyList extends PersistentList{
return this;
}
+ public IPersistentList pop(){
+ throw new IllegalStateException("Can't pop empty list");
+ }
+
public ISeq seq(){
return null;
}