On 21 March 2011 11:29, Chas Emerick <[email protected]> wrote:
> The notion of "passing around Clojure data structures" does get watered down
> because of the non-sexpr-nature of e.g. *out* and *err*, and it's all
> message-oriented so as to support asynchronous evaluation from the same
> client, but that's pretty much what nREPL does. Expressions are sent,
> results are printed and sent back.
That wasn't quite what I meant :)
You could use a Clojure data structure protocol (henceforth known as
CDSP) to send the just data you want evaluated by the REPL, e.g.
>>> (+ 1 1)
<<< 2
But that's probably too simplistic. Instead, you'd probably encase
messages in a map, e.g.
>>> {:id 1, :eval (+ 1 1)}
<<< {:id 1, :return 2}
Which would allow you to handle more sophisticated streaming stuff as well:
>>> {:id 2, :eval (do (Thread/sleep 1) (print "world"))}
>>> {:id 3, :eval (print "hello")}
<<< {:id 3, :out "hello"}
<<< {:id 3, :return nil}
<<< {:id 2, :out "world"}
<<< {:id 2, :return nil}
My point was more that network protocols should be designed in layers.
Take a streaming protocol like TCP, layer netstrings on top of it so
you have a safe way of passing fixed-length messages. Then use the
Clojure read-string and pr-str functions to encode data.
You then have a very basic protocol that allows you to communicate in
more complex data structures, like maps, vectors and lists, which you
can use as a basis for a more sophisticated protocol.
In essence, we want to build a compound network protocol out of simple
components. You don't have to use netstrings and Clojure data
structures to do it, but they seem like a good fit.
- James
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en