Fork me on GitHub

Hello all, I’m a total newcomer to nrepl and I have a question about embedding an nrepl server in an application. I would like to automatically define some symbols whenever a client connects (new sessions). I thought the :greeting-fn might fit this need, so I tried this:

(start-server :greeting-fn (fn [t]
                             (-> t
                                 (nt/send {:out "Hello!"})
                                 (nt/send {:eval "(def x 10)"}))))
When I connect to the repl, I see the “Hello!” but the x symbol is not defined. Am I going about this incorrectly? Does anyone have any suggestions for how best to implicitly evaluate a form when a client connects? Thanks.


transport is how the server you are starting talks to the client. you can't ask the client to eval something, the server has to eval that. have you tried just (fn [t] (def x 10))? I can't imagine it's in the correct namespace though


Ah ok thanks, @dpsutton. I see that understood the directionality of the transport wrong. Can you elaborate on your suggestion a little more? Where would you suggest I try putting the (fn [t] (def x 10))?


your greeting function