Hacker News new | ask | show | jobs
by tome 3156 days ago
Thanks, that's very helpful.

As a Haskell programmer I already know the benefits of 3! 1 and 2 are things that I don't take advantage of so I have a couple more questions.

1. Is this like a Jupyter notebook or some different sort of functionality?

2. Does it work for integer values, say, as well as functions? Suppose my source code says

    x = 1
and in my REPL I write

    y = 10 + x
and then I change my source code to

    x = 2
and reload the REPL. Then is y 11 or will y be updated to 12?
1 comments

Is this like a Jupyter notebook or some different sort of functionality?

Its similar in some ways, but not quite exactly the same thing. The repl is a server, and doesn't have an interface. So it reads over a socket port, and prints a response back over the socket using a common protocol. So you can build any client you want for it. What is most common is to take an existing editor, like emacs, vim, eclipse, atom, etc. And write a plugin for them which interacts with the server repl. So say your in eclipse, you have a Clojure project open, you can have eclipse send your project code to the repl for you. In practice that means you just work on your code files directly, and just sync them to the repl as you go. Some clients try to be even fancier, creating visual representation of code output like graphs, or gui controls like drilling into a nested map.

Does it work for integer values, say, as well as functions? Suppose my source code says

Y would be 12.

(let [x 1 y (+ 10 x)] y)

If you load this it'll return 11. If you change x to 2 and reload this, it will return 12.

Globally you'd do:

(def x 1) (def y (+ 10 x)

Now y is equal to 11. If you change x to 2, and only reload x, y would still be equal to 11. You'd have to reload y also if you want it to be 12 now.

That's because y is bound to the value of the expression, not to the expression itself. And the value is calculated at load time.

Now you could bind it to the expression by using a function.

(def x 1) (def y #(+ 10 x)

#() is Clojure's shorthand for lambda.

So now the caller is in charge of deciding when to evaluate y.

Calling: (y)

Would return 11 and if you change x to 2, calling it again would return 12.

You can also use reactive constructs instead. So when setting x to 2, an event is published, so you can listen to it and have it reset y to the new value of evaluating (+ 10 x).