Fork me on GitHub
#nrepl
<
2021-05-20
>
Eddie05:05:35

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.

dpsutton05:05:37

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

Eddie17:05:02

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))?

dpsutton17:05:44

your greeting function