nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
Eddie 2021-05-20T05:15:35.009300Z

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.

dpsutton 2021-05-20T05:43:37.010400Z

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

Eddie 2021-05-20T17:16:02.012300Z

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

dpsutton 2021-05-20T17:16:44.012500Z

your greeting function