Re: There is no such thing as IAtom

2010-12-07 Thread pepijn (aka fliebel)
Thanks all.

How would I do this protocol extension thing? My guess is that I need
to define the IAtom protocol myself, and then do something like this?

(defprotocol IAtom
  (compare-and-set! [])
  ...)

(extend-type clojure.lang.Atom
  IAtom
  (compare-and-set! [])
  ...
  IDeref
  (deref []))

But will that pass a Atom type hint? I will play with it and see for
myself. Thanks.

On Dec 6, 7:08 pm, Alyssa Kwan  wrote:
> +1
>
> There is no STM integration with atoms.  That's not a concern.
>
> Just write your own Clojure core with your change.  I did for durable
> identities.  git://github.com/kwanalyssa/clojure.git shamelessPlug>
>
> Seriously though, just use protocols.
>
> Thanks,
> Alyssa
>
> On Dec 6, 5:24 am, Benjamin Teuber  wrote:
>
>
>
>
>
>
>
> > I guess it was Rich's intention to have swap! be used for real atoms
> > only so your code remains understandable - that's why it's called
> > swap! for atoms, alter for refs and alter-var-root for vars.
>
> > So why not define your own protocol for updating documents? If you
> > really want (usually bad idea, I guess) you could still extend atoms
> > or even refs to support this protocol, too.
>
> > Regards,
> > Benjamin
>
> > On 5 Dez., 23:29, Pepijn de Vos  wrote:
>
> > > tl;dr: Please add an interface to clojure.lang.Atom. kthxbye
>
> > > I had the brilliant idea of using CouchDB for something equally 
> > > brilliant, and if possible implement a Clojure view server. Turns out 
> > > Clutch fits the bill perfectly, except that I would like to use Aleph, 
> > > and Couch is using something called MVCC.
>
> > > I haven't looked into the libs to deep, but I know the REST API, and what 
> > > it does for updating is that you need to supply the current revision and 
> > > if it doesn't match (i.e. there has been another update), the update 
> > > fails. So then you need to get the new _rev and try again. Much the same 
> > > way compare-and-set! works.
>
> > > I thought it would be perfect to implement IAtom and IDeref to get the 
> > > latest value and to swap! documents in a spin loop with a 
> > > side-effect-free function, like atoms do.
>
> > > But it turns out there is no interface for Atom and it is marked final. 
> > > The same is true for Ref and Agent, but raek suggested this might be 
> > > because they are more complex and integrated with the STM.
>
> > > Is there a good reason why I'm not allowed to implement my own atom? If 
> > > not, can it be added? Thanks.
>
> > > Groeten,
> > > Pepijn de Vos
> > > --
> > > Sent from my iPod Shufflehttp://pepijndevos.nl-Hide quoted text -
>
> > - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: There is no such thing as IAtom

2010-12-06 Thread Alyssa Kwan
+1

There is no STM integration with atoms.  That's not a concern.

Just write your own Clojure core with your change.  I did for durable
identities.  git://github.com/kwanalyssa/clojure.git

Seriously though, just use protocols.

Thanks,
Alyssa

On Dec 6, 5:24 am, Benjamin Teuber  wrote:
> I guess it was Rich's intention to have swap! be used for real atoms
> only so your code remains understandable - that's why it's called
> swap! for atoms, alter for refs and alter-var-root for vars.
>
> So why not define your own protocol for updating documents? If you
> really want (usually bad idea, I guess) you could still extend atoms
> or even refs to support this protocol, too.
>
> Regards,
> Benjamin
>
> On 5 Dez., 23:29, Pepijn de Vos  wrote:
>
>
>
> > tl;dr: Please add an interface to clojure.lang.Atom. kthxbye
>
> > I had the brilliant idea of using CouchDB for something equally brilliant, 
> > and if possible implement a Clojure view server. Turns out Clutch fits the 
> > bill perfectly, except that I would like to use Aleph, and Couch is using 
> > something called MVCC.
>
> > I haven't looked into the libs to deep, but I know the REST API, and what 
> > it does for updating is that you need to supply the current revision and if 
> > it doesn't match (i.e. there has been another update), the update fails. So 
> > then you need to get the new _rev and try again. Much the same way 
> > compare-and-set! works.
>
> > I thought it would be perfect to implement IAtom and IDeref to get the 
> > latest value and to swap! documents in a spin loop with a side-effect-free 
> > function, like atoms do.
>
> > But it turns out there is no interface for Atom and it is marked final. The 
> > same is true for Ref and Agent, but raek suggested this might be because 
> > they are more complex and integrated with the STM.
>
> > Is there a good reason why I'm not allowed to implement my own atom? If 
> > not, can it be added? Thanks.
>
> > Groeten,
> > Pepijn de Vos
> > --
> > Sent from my iPod Shufflehttp://pepijndevos.nl- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: There is no such thing as IAtom

2010-12-06 Thread Stuart Sierra
On Dec 6, 11:52 am, "pepijn (aka fliebel)" 
wrote:
> You can not extend them, as they are marked final.

You can extend Clojure protocols to final classes.

> Another point to consider is clojure-in-clojure. If that is ever going
> to happen, one needs to be able to implement Atom as well.

clojure-in-clojure will probably be defined in terms of protocols.
Whether or not "IAtom" is one of those I can't say.

-S

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: There is no such thing as IAtom

2010-12-06 Thread pepijn (aka fliebel)
You can not extend them, as they are marked final.

Another point to consider is clojure-in-clojure. If that is ever going
to happen, one needs to be able to implement Atom as well. It is also
generally better to code to an interface rather than to an
implementation.

Alter and send also work differently from swap!, so I think it makes
sense to have separate functions for them. But CouchDB also exhibits
shared, synchronous, independent state, so I don't see the point in
prohibiting the use of the same interface.

On Dec 6, 11:24 am, Benjamin Teuber  wrote:
> I guess it was Rich's intention to have swap! be used for real atoms
> only so your code remains understandable - that's why it's called
> swap! for atoms, alter for refs and alter-var-root for vars.
>
> So why not define your own protocol for updating documents? If you
> really want (usually bad idea, I guess) you could still extend atoms
> or even refs to support this protocol, too.
>
> Regards,
> Benjamin
>
> On 5 Dez., 23:29, Pepijn de Vos  wrote:
>
>
>
>
>
>
>
> > tl;dr: Please add an interface to clojure.lang.Atom. kthxbye
>
> > I had the brilliant idea of using CouchDB for something equally brilliant, 
> > and if possible implement a Clojure view server. Turns out Clutch fits the 
> > bill perfectly, except that I would like to use Aleph, and Couch is using 
> > something called MVCC.
>
> > I haven't looked into the libs to deep, but I know the REST API, and what 
> > it does for updating is that you need to supply the current revision and if 
> > it doesn't match (i.e. there has been another update), the update fails. So 
> > then you need to get the new _rev and try again. Much the same way 
> > compare-and-set! works.
>
> > I thought it would be perfect to implement IAtom and IDeref to get the 
> > latest value and to swap! documents in a spin loop with a side-effect-free 
> > function, like atoms do.
>
> > But it turns out there is no interface for Atom and it is marked final. The 
> > same is true for Ref and Agent, but raek suggested this might be because 
> > they are more complex and integrated with the STM.
>
> > Is there a good reason why I'm not allowed to implement my own atom? If 
> > not, can it be added? Thanks.
>
> > Groeten,
> > Pepijn de Vos
> > --
> > Sent from my iPod Shufflehttp://pepijndevos.nl

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: There is no such thing as IAtom

2010-12-06 Thread Benjamin Teuber
I guess it was Rich's intention to have swap! be used for real atoms
only so your code remains understandable - that's why it's called
swap! for atoms, alter for refs and alter-var-root for vars.

So why not define your own protocol for updating documents? If you
really want (usually bad idea, I guess) you could still extend atoms
or even refs to support this protocol, too.

Regards,
Benjamin

On 5 Dez., 23:29, Pepijn de Vos  wrote:
> tl;dr: Please add an interface to clojure.lang.Atom. kthxbye
>
> I had the brilliant idea of using CouchDB for something equally brilliant, 
> and if possible implement a Clojure view server. Turns out Clutch fits the 
> bill perfectly, except that I would like to use Aleph, and Couch is using 
> something called MVCC.
>
> I haven't looked into the libs to deep, but I know the REST API, and what it 
> does for updating is that you need to supply the current revision and if it 
> doesn't match (i.e. there has been another update), the update fails. So then 
> you need to get the new _rev and try again. Much the same way 
> compare-and-set! works.
>
> I thought it would be perfect to implement IAtom and IDeref to get the latest 
> value and to swap! documents in a spin loop with a side-effect-free function, 
> like atoms do.
>
> But it turns out there is no interface for Atom and it is marked final. The 
> same is true for Ref and Agent, but raek suggested this might be because they 
> are more complex and integrated with the STM.
>
> Is there a good reason why I'm not allowed to implement my own atom? If not, 
> can it be added? Thanks.
>
> Groeten,
> Pepijn de Vos
> --
> Sent from my iPod Shufflehttp://pepijndevos.nl

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en