问题
I am curious if it is possible to write a function in clojure that can be called from the repl without opening and closing parentheses. I use for example always the following function:
(defn ll [] (load-file "D:\\work.clj"))
I have to call this with (ll) but it would come in handy if only ll was needed.
[My idea comes from autocad/autolisp. In there I can define a function like (defun c:somecommand () . . )
From this point on I can use somecommand on the commandline (because of 'c:' before the command. Without parentheses.]
回答1:
You could, but you shouldn't ;)
Here's an example that misuses (IMHO) reify to override .toString
to have a side-effect.
(def m (reify Object (toString [this] (println "Evil side effect") "foo")))
#'user/m
user=> m
Evil side effect
#object[user$reify__151 0x3350ebdd "foo"]
来源:https://stackoverflow.com/questions/61233652/using-clojure-in-repl-without-opening-en-closing-parentheses