drlivingston / kr

Clojure API for RDF and SPARQL - provides consistent access to APIs including Jena and Sesame
56 stars 17 forks source link

keywords instead of symbols? #1

Open ghost opened 12 years ago

ghost commented 12 years ago

Hello,

it's not really an "issue" - I'm just wondering is there a reason to use symbols as elements of triplets? In clojure, keywords usually used in such cases: [:ex/KevinL :foaf/name "Kevin Livingston"].

Thanks for your work and good luck with the new library!

drlivingston commented 12 years ago

Hi Dmitri, thanks for the interest and the question...

I came from a CommonLisp background, over there keywords are in the keyword namespace unlike Clojure keywords. It was just natural to make them this way. (also less typing ;) In Clojure I guess there's no reason they couldn't be, they have a namespace and a name which is what's really needed. There are a few places where keywords matter, and have specific meaning in the library, for example things like :optional or :union in the SPARQL pattern API. ... these could still be detected if you were to use keywords as the Clojure form of resources. The library could I suppose be made to recognize and output keywords, but you would have to pick keywords or not because clj-ify (the operation that turns things from the other libraries into Clojure datatypes would have to know what to choose), and having multiple forms would interfere with the ability to use Clojure equality operators.

With keywords it would be a little easier to control empty namespace things, so you could have :?foo instead of ?/foo for variables (as the library uses), but that's still not ?foo which is more typical, but impossible(?) to generate inside a backtick... and you could let the namespace be whatever for ?foo but then you would need specialized equality and lookup operators everywhere...

Right now I'm reasonably happy to use symbols and have special namespaces including ?/ and _/ (for variables and blank nodes)... it seems to be working well, but that's not to say I'm closed to discussion on it, I would be happy to look more into the relative merits and disadvantages of either/any choice, so that the best one is made.

As a side note, it just looks at sequences so vectors or lists should be just fine (although I don't know if there are tests for this, I should add some).

thanks, Kevin

ghost commented 12 years ago

Oops! Sorry for such a late response!

Of course, keywords vs. symbols problem doesn't really affects the functionality or something like that; it's mostly about how the API feels. In clojure, symbols are used much less frequently than in CL. Generally, only macros work with them, so you rarely have to quote something before passing in function (standalone use, require and import are an annoying exception to the rule). The same with vectors: since you have literal vector, why use quoted list?

Another thing is that every symbol creates unique object under the hood (while keywords use pool), thus it's pretty heavyweight compared to keywords (although it's hardly matters in this case).

Anyway, it's just a minor style thing, so if changing it would require additional work then it doesn't worth the time spent.