Closed viebel closed 6 years ago
I can understand this but the var is the value that is returned by the expression.
We wouldn't want folks to think they can do this (def a (def b 2))
.
That being said you should be able to configure rebel-readline to print the final value however you want. Rebel-readline offers an api that you can use to compose the REPL experience that you want.
If you want to be able to specify say a middleware that filters values before they are printed in the .rebel-readline config file that might be an interesting configuration point.
It would be interesting to support pretty printing this way as well.
I would need to look back into it and see if there is a good pattern that expresses this kind of customization.
On Thu, Sep 27, 2018 at 1:04 AM Yehonathan Sharvit notifications@github.com wrote:
Is there a way to config rebel-readline so that it displays values instead of var when evaluating a def form?
Currently it works like this:
user=> (def abc 42)
'user/abc
Would it be possible to make it work like that:
user=> (def abc 42)42
The reason I am asking for this feature is that it is a bit hard for Clojure beginners to understand the concepts of var. Displaying values instead of vars will make rebel-readline more beginner friendly.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bhauman/rebel-readline/issues/178, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAKQCCCN9tkqC0yk_P4laPc4DZdOS0nks5ufFx6gaJpZM4W76kg .
I happened to create my own repl with the following code:
Is this what you meant?
(ns klipse-repl.main
(:require
[rebel-readline.core :refer [with-readline-in]]
[rebel-readline.clojure.line-reader :as line-reader]
[rebel-readline.clojure.service.local :as rebel-service]
[clojure.main :as clojure-main]))
(defn custom-eval [x]
(let [res (eval x)]
(if (seq? x)
(cond
(= 'def (first x)) @res
(= 'defn (first x)) (symbol (str "Function " (:name (meta res)) " created"))
:else res)
res)))
(defn -main []
(with-readline-in
(line-reader/create
(rebel-service/create))
(clojure-main/repl
:init (fn [] (println "klipse-repl"))
:eval custom-eval
:prompt (fn []))))
Yeah that works! I realized after I sent the email that this is the only way for you to do this because you have to know what was evaluated.
Cool!
Is there a way to config
rebel-readline
so that it displays values instead of var when evaluating adef
form?Currently it works like this:
Would it be possible to make it work like that:
The reason I am asking for this feature is that it is a bit hard for Clojure beginners to understand the concepts of
var
. Displaying values instead of vars will makerebel-readline
more beginner friendly.