Mark Engelberg <mark.engelb...@gmail.com> writes: > But let's say later you decide you want your data model to be {:first-name > "Alice", :last-name "Beasley", :email "al...@example.com"}, and you want to > change name to be a computed value that concatenates first and last names > -- this is going to break all your existing code. If name were only > accessed throughout your code via the call `get-name`, then it would be > trivial to make this change. > > (Theoretically, it is possible to implement a revision to a person data > structure by representing it as a custom map that reimplements keyword > access so that (:name person) calls a function rather than does the usual > keyword lookup, but I've never seen anyone do this, so I'm ignoring this > possibility for the purpose of this discussion).
Actually, I think that this is a real problem with Clojure, and with data access. It is very hard to change between accessing a var as a value and through calling a value. I can give two concrete examples of this. First, in my library I used a var to store a factory object from a Java API. So I created one and stored it in a var. This worked well, in general, but when I integrated my library into an application, I realised that I need to get this factory object from elsewhere -- in short I needed a function call. So I had to change all of my `data-factory` calls to `(data-factory)`. Another time the same issue hit me was with Clojure's :doc metadata. This is stored as a string, but I wanted to be able to subvert this by calculating the string from the object containing in the var. As far as I can tell, this is impossible in Clojure without changing all the client code that accesses the :doc metadata. Java does not have this problem by common design patterns -- fields are declared private and always accessed through a function. If I understand things correctly, Scala avoids the problem in the same way, although it autocodes the accessors for you, so avoids the boilerplate. In Clojure, it seems the only way to avoid this would to wrap up values in `constantly` and access everything as a function. Phil -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.