Re: Specialize collection

2011-02-17 Thread Ken Wesson
You can also create new types that act mostly like Clojure's existing types using deftype and implementing things like IPersistentStack. I posted code for (among other things) a bounded deque (using a ringbuffer internally) here fairly recently. The one limitation with these things is that they d

Re: Specialize collection

2011-02-17 Thread pba
The code from my previous post is not correct, cons for example affects metadata: (def q (bounded-queue 3)) (meta q) -> { :bounded-size 3} (meta (cons 1 qm)) -> nil On Feb 17, 3:19 pm, pba wrote: > Combining the two approaches: > (defn bounded-queue [size] >    (with-meta (clojure.lang.Persisten

Re: Specialize collection

2011-02-17 Thread pba
Combining the two approaches: (defn bounded-queue [size] (with-meta (clojure.lang.PersistentQueue/EMPTY) {:bounded-size size})) then look for (get (meta q) :bounded-size) in the protocol. Nice ... Thanks! On Feb 17, 11:04 am, Alexandre Patry wrote: > On 11-02-17 10:33 AM, pba wrote:> Not qui

Re: Specialize collection

2011-02-17 Thread Alexandre Patry
On 11-02-17 10:33 AM, pba wrote: Not quite, the queue size needs to be passed in at instantiation time for example you may want to have a 10 or 100 element queue depending on the element type. What I'm looking for is to somehow decorate the queue (or some other object) with behavior constraints (

Re: Specialize collection

2011-02-17 Thread pba
Not quite, the queue size needs to be passed in at instantiation time for example you may want to have a 10 or 100 element queue depending on the element type. What I'm looking for is to somehow decorate the queue (or some other object) with behavior constraints (a la C++ traits) when the object is

Re: Specialize collection

2011-02-17 Thread Michael Fogus
> Is there a better way to specialize an built-in Clojure collection > except wrapping - like for example to create a fixed size queue that > drops new elements while full ? You can use protocols as in the example at https://gist.github.com/831830 Is this what you were looking for? -- You recei

Specialize collection

2011-02-17 Thread pba
Is there a better way to specialize an built-in Clojure collection except wrapping - like for example to create a fixed size queue that drops new elements while full ? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email t