On Mar 19, 2009, at 2:14 PM, mikel wrote:

>
>
>
> On Mar 19, 7:17 am, David Nolen <[email protected]> wrote:
>> Doesn't On Lisp talk about simulating CLOS with closures? It's free  
>> online.
>
> Building either class-based or prototype-based object systems on
> closures is pretty straightforward. A closure carries abritrary state
> around in the closed-over lexical environment. Make the closure
> function a suitable dispatching function, and you can then use it as a
> building block to build any sort of object system you like. Probably
> you then want to write some macros to provide a graceful syntax for
> interacting with whatever object system it is you've invented.
>

This style of 'object' system is somewhat complicated/precluded by the  
fact that, in Clojure, locals are immutable, thus any such object  
would be immutable too. That's not what you'll see in the books, where  
closed-over locals act as mutable fields of the object. Closing over  
individually mutable things like refs or atoms, while possible, would  
really be missing the point of Clojure's approach to programming with  
values. If someone's going to do an object system for Clojure, it  
should be one in which the entire state of an object is available as a  
value.

http://clojure.org/state

>
>> I would like to add as the creator that I would not use Spinoza  
>> yet ;) And
>> I've put it on hold as I'm currently obsessed with trying to port  
>> cl-cont.
>>  Spinoza still needs quite a bit of work, I started on that before  
>> a few
>> things changed in Clojure.  I will get back to it.  Having now  
>> played with
>> Clojure for a bit I'm not sure how useful Spinoza will turn out to  
>> be for
>> anything beyond supporting widgets in a web framework.  With  
>> Clojure's
>> flexibility it's really tough to come up with reasons to resort to  
>> an object
>> system.
>> That said, it at least shows that building a more traditional class  
>> system
>> is not very difficult in Clojure.
>
> And, as you suggest, probably not needed. After experimenting with
> data structures in my application, I'm satisfied with maps and
> sequences, though I have added a few utilities for making expected and
> required fields and arguments more explicit in my source.
>
> The part of CLOS that I actually want is generic functions. I also
> experimented with making my own gf implementation, then switched my
> app back and forth between that and Clojure's multifns a few times to
> see whether I really prefer gfs. Turns out I do, so I'm plowing some
> more work into the gf implementation.

What specifically about gfs do you miss/prefer?

Rich


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to