Laurent PETIT wrote: > To simplify a little bit (both from a library implementor and user > perspective), why not get rid of the appended dash - ? > > Indeed, having an appended dash suggests to me (so it's not apparent > from the examples) that the user will have to access, for a same object, > data sometimes from key accessors, and sometimes from specific function > accessors.
Here's my line of thought that lead to adding the suffixes. In order to encapsulate access to a data type, it must only be used via the designated accessor functions. The dash in the key name is there to act as a reminder of that. If you use the symbol to get a field's value anywhere outside the field's accessor function, it means you're doing something you're not supposed to do. I thought that I'd mark all the fields in the struct as "private" like that to make the clients think twice before circumventing an accessor function. ; A regular struct, so this is OK (do-something (my-own-struct :foobar)) ; Circumventing an accessor - this is risky (and looks wrong)! (do-something-else (encapsulated-struct :foobar-)) A Java analog in a parallel universe where there's no "private" keyword: // Circumventing an accessor - this is risky (and looks wrong)! doSomethingElse(anotherObject.m_foobar); > I don't know if the whole common lisp "structs" library has been ported > to clojure. > And, as you asked, I'm not sure whether this would be a good think to > port it, and if there's another idiomatic way to solve the same problems. Unfortunately I have no prior experience with Lisp. That's probably why I'm so at loss with something this elementary! Frankly, I'm a bit afraid that I might be looking for a solution to a problem that doesn't even come up in proper Lisp programs. I need a book called "Clojure for OO Programmers"... :) -- Timo --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---