Re: Adding implicit indexing to Clojure lists and arrays?

2013-07-03 Thread david
(defn indexed "Returns a lazy sequence of [index, item] pairs, where items come from 's' and indexes count up from zero. (indexed '(a b c d)) => ([0 a] [1 b] [2 c] [3 d])" [s] (map vector (iterate inc 0) s)) -- -- You received this message because you are subscribed to the Google Grou

Re: Adding implicit indexing to Clojure lists and arrays?

2013-06-28 Thread Mikera
Mike or mikera is fine :-) If you wanted to provide this kind of functionality, I'd normally suggest doing it with a protocol. Something like: (defprotocol PWrappedIndex (get-wrapped [coll index])) (extend-protocol PWrappedIndex clojure.lang.Indexed (get-wrapped [coll index] (nth

Re: Adding implicit indexing to Clojure lists and arrays?

2013-06-27 Thread Greg
Thanks Mike (or do you go by "Mikera" as your email alias suggests?), I think you make very good points, so I withdraw my request. I'm curious though... Just as a learning experience, would it be possible to "tack on" such syntax implicit indexing and slicing using Clojure's extend-type functio

Re: Adding implicit indexing to Clojure lists and arrays?

2013-06-27 Thread Mikera
I agree that negative indexing (and presumably also modulo indexing for the upper index?) is very useful. Stuff like this comes up all the time in core.matrix However I don't think it makes sense as a standard feature in Clojure's low-level data constructs for several reasons: a) It's a breakin

Re: Adding implicit indexing to Clojure lists and arrays?

2013-06-26 Thread Cedric Greevey
(v 0) and the like already work when v is a vector. You can also do something like this: (defn proper-rem [a b] (if (neg? a) (dec (- b (rem (- (inc a)) b))) (rem a b))) (defn at [v idx] (v (proper-rem idx (count v (defn r [start end v] (let [c (count v) s (proper-rem st

Re: Adding implicit indexing to Clojure lists and arrays?

2013-06-26 Thread Michael-Keith Bernard (SegFaultAX)
Vectors and maps are already functions of their indices and keys, respectively. I don't really think it makes sense for other sequence types (seqs, lists, etc.) because they aren't naturally associative in the same way. Finally, there isn't a Clojure form I'm aware of that allows negative indic

Adding implicit indexing to Clojure lists and arrays?

2013-06-26 Thread Greg
There is one feature that I really miss from newLISP and seems like it could be a natural extension to Clojure, and that is implicit indexing for lists and arrays. Clojure already has something similar in its use of keywords to act as functions that look themselves up in a map. This is basical