On 24.04.2010, at 05:48, Mark Engelberg wrote:

> As far as I know, Clojure doesn't currently make any attempt to
> address this problem of allowing a standard way to access public data
> from an object, while preserving the option of doing something more
> sophisticated later.  So a programmer is still forced to choose
> between the convenience of keyword lookup of data, versus a protocol
> filled with "get-name" functions to preserve future flexibility.

This is basically a question of how you choose your abstractions (the 
documented interfaces) and your implementations (the data structures), and in 
particular on where you draw the boundaries. That is a design issue, so I don't 
expect any language feature to remove the necessity to think about this 
carefully.

> For this reason, I've always found appealing languages which let you
> optionally write getter/setter methods that "hook into" the standard
> field access syntax.

That's little more than syntactic sugar, considering that field access is 
equivalent to calling a method with no arguments.

The closest equivalent in Clojure would be to define a functional accessor API 
for all access to your data. A first implementation would simply set the 
accessor to be a field-name keyword:

        (defrecord foo [bar baz])
        (def get-bar :bar)
        (def get-baz :baz)

If necessary you can then replace the accessor functions by something more 
complicated, or turn them into prototype functions to allow multiple 
implementations. Client code won't see the difference.

Konrad.

-- 
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

Reply via email to