Re: Modifying data structures without changing their interface

2009-04-21 Thread Kyle Schaffrick
On Mon, 20 Apr 2009 21:53:41 +0200 Laurent PETIT laurent.pe...@gmail.com wrote: Hi David, 2009/4/20 David Nolen dnolen.li...@gmail.com: A couple of things. In your initial example, you conflated some things. One issue is simply a matter of convenience- defining a getter so that you

Re: Modifying data structures without changing their interface

2009-04-20 Thread Timo Mihaljov
Timo Mihaljov wrote: I'm wondering about how to change a data structure without breaking the API used to access it. For example, let's assume that I have a library for dealing with records of people and I'm storing them in structs. (defstruct person :name) The users of my library

Re: Modifying data structures without changing their interface

2009-04-20 Thread Laurent PETIT
Hi, 2009/4/20 Timo Mihaljov noid@gmail.com Timo Mihaljov wrote: I'm wondering about how to change a data structure without breaking the API used to access it. For example, let's assume that I have a library for dealing with records of people and I'm storing them in structs.

Re: Modifying data structures without changing their interface

2009-04-20 Thread Timo Mihaljov
Laurent PETIT wrote: While interesting, this approach seems to me limited to simple cases : * limited in possibilities: you are not able to directly use values of other fields. So in more complex cases, you won't be able to combine calculated values without code repetition or prepraration

Re: Modifying data structures without changing their interface

2009-04-20 Thread Laurent PETIT
Hi, 2009/4/20 Timo Mihaljov noid@gmail.com Laurent PETIT wrote: While interesting, this approach seems to me limited to simple cases : * limited in possibilities: you are not able to directly use values of other fields. So in more complex cases, you won't be able to combine

Re: Modifying data structures without changing their interface

2009-04-20 Thread Timo Mihaljov
Laurent PETIT wrote: What do others think about these 2 above statements ? The standard OO approach to information hiding would be private fields and accessor methods. Any suggestions for the One True Clojure Pattern that addresses the same problem? I think accessor

Re: Modifying data structures without changing their interface

2009-04-20 Thread Matt Clark
Maybe I'm missing something, but what is wrong with Stuart Sierra's solution? I quite like it, and it would probably be more appealing if it were encapsulated into a macro. (def-propholder person) (def me (person {:name Matt Clark})) (def-propholder person2 :name {:getter (fn [record]

Re: Modifying data structures without changing their interface

2009-04-20 Thread Stuart Sierra
On Apr 20, 12:32 pm, Laurent PETIT laurent.pe...@gmail.com wrote: I think you Timo ask here a very interesting and important question. It's not just about having encapsulation or not. It's really about designing the code so that the library internals can evolve without impact on the user

Re: Modifying data structures without changing their interface

2009-04-20 Thread Laurent PETIT
Hi David, 2009/4/20 David Nolen dnolen.li...@gmail.com: A couple of things. In your initial example, you conflated some things. One issue is simply a matter of convenience- defining a getter so that you can use Python object property access (via the dot operator). Personally I don't like

Re: Modifying data structures without changing their interface

2009-04-20 Thread Mark Engelberg
On Mon, Apr 20, 2009 at 1:27 PM, Bradbev brad.beveri...@gmail.com wrote: If you promise that functions will accept and return maps with certain keys, then you must keep that promise moving forward. I think you're missing part of the point of the original post. You don't really want to

Re: Modifying data structures without changing their interface

2009-04-20 Thread mikel
On Apr 20, 4:17 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Apr 20, 2009 at 1:27 PM, Bradbev brad.beveri...@gmail.com wrote: If you promise that functions will accept and return maps with certain keys, then you must keep that promise moving forward. I think you're

Re: Modifying data structures without changing their interface

2009-04-20 Thread Bradbev
On Apr 20, 2:17 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Apr 20, 2009 at 1:27 PM, Bradbev brad.beveri...@gmail.com wrote: If you promise that functions will accept and return maps with certain keys, then you must keep that promise moving forward. I think you're missing

Modifying data structures without changing their interface

2009-04-19 Thread Timo Mihaljov
Hi, I'm wondering about how to change a data structure without breaking the API used to access it. For example, let's assume that I have a library for dealing with records of people and I'm storing them in structs. (defstruct person :name) The users of my library access the data stored

Re: Modifying data structures without changing their interface

2009-04-19 Thread Stuart Sierra
On Apr 19, 11:00 am, Timo Mihaljov noid@gmail.com wrote: I'm wondering about how to change a data structure without breaking the API used to access it. For example, let's assume that I have a library for dealing with records of people and I'm storing them in structs.      (defstruct

Re: Modifying data structures without changing their interface

2009-04-19 Thread James Reeves
On Apr 19, 4:00 pm, Timo Mihaljov noid@gmail.com wrote: What's the idiomatic Clojure way of dealing with this issue? I'd be tempted to use accessor functions, like: (defn get-name [person] (:name person)) When the data structure changes, I update the function: (defn get-name