Using Clojure in Repl without opening en closing parentheses

为君一笑 提交于 2021-02-11 15:48:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!