Hi -
I've been working on Bulbs/Clojure the last few weeks and have been using this as an opportunity to learn the language.
Clojure's functional style has taken a bit to get used to, but I'm starting to get a feel for it and like it a lot.
I'm playing around with different designs, and right now I'm defining graph as a higher-order function that returns an anonymous function with an instance of the server's client object in its scope (i.e. either the Neo4j Server or Rexster client)...
(ns bulbs.neo4jserver.graph
(:use [bulbs.neo4jserver.client :only [create-client]]))
(defn graph
"Returns a function that takes a function and its args."
[& [config]]
(use '[bulbs.element :only (vertex edge)])
(alias 'bulbs 'bulbs.element)
(let [client (create-client config)]
(fn [func element & args]
(apply func (assoc element :client client) args))))
You pass in functions to graph which are then dispatched on the argument type (e.g. either "vertex" or "edge")...
;; Bulbs/Clojure example
user> (use '[bulbs.neo4jserver.graph :only (graph)])
user> (def g (graph))
user> (def james (g bulbs/create vertex {:name "James"}))
user> (def julie (g bulbs/create vertex {:name "Julie"}))
user> (g bulbs/create edge james :knows julie)
I'm trying to keep the interface close to Bulbs/Python -- here's a comparison...
# Bulbs/Python example
>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> james = g.vertices.create(name="James")
>>> julie = g.vertices.create(name="Julie")
>>> g.edges.create(james, "knows", julie)
I'll post the 0.1 to GitHub in a few days. If there are any Clojure gurus on the list, let me know -- feedback welcome!
- James