diff options
-rw-r--r-- | clojure.markdown | 5 | ||||
-rw-r--r-- | src/jvm/clojure/lang/PersistentVector.java | 6 |
2 files changed, 6 insertions, 5 deletions
diff --git a/clojure.markdown b/clojure.markdown index 713f02e7..f8b6394a 100644 --- a/clojure.markdown +++ b/clojure.markdown @@ -476,7 +476,7 @@ Same as `first`. Returns the first item in the list. If the list is empty, retur Returns a new list without the first item. If the list is empty, throws an exception. Note - *not* the same as `rest`. ### _Vectors (IPersistentVector)_ -Vectors are collections. They are sequences of values indexed by contiguous integers. Vectors support O(log32N) access to items by index. `count` is O(1). `conj` puts the item at the end of the vector. In addition, vectors support the functions: +Vectors are collections. They are sequences of values indexed by contiguous integers. Vectors support O(log32N) access to items by index. `count` is O(1). `conj` puts the item at the end of the vector. Vectors also support `rseq`, which returns the items in reverse order. Vectors implement IFn, for invoke() of one argument, which they presume is an index and look up in themselves as if by `nth`, i.e. vectors are functions of their indices. In addition, vectors support the functions: --- ### (*vector* & items) @@ -541,9 +541,6 @@ Returns a sequence of the map's keys. --- ### (*vals* map) Returns a sequence of the map's values. - -### _Vectors (IPersistentVector)_ - <h2 id="metadata">Metadata</h2> diff --git a/src/jvm/clojure/lang/PersistentVector.java b/src/jvm/clojure/lang/PersistentVector.java index d45ef2dc..752b4c8b 100644 --- a/src/jvm/clojure/lang/PersistentVector.java +++ b/src/jvm/clojure/lang/PersistentVector.java @@ -14,7 +14,7 @@ package clojure.lang; import java.util.*; -public class PersistentVector extends Obj implements IPersistentVector, Iterable{ +public class PersistentVector extends AFn implements IPersistentVector, Iterable{ final int cnt; final int shift; final Object[] root; @@ -162,6 +162,10 @@ public PersistentVector withMeta(IPersistentMap meta){ return new PersistentVector(meta, cnt, shift, root); } +public Object invoke(Object arg1) throws Exception{ + return nth(((Number) arg1).intValue()); +} + public Iterator iterator(){ //todo - something more efficient return new Iterator(){ |