在Repl中使用Clojure而不用打开括号 [英] Using Clojure in Repl without opening en closing parentheses
问题描述
我很好奇是否有可能在clojure中编写一个可以从repl调用而无需打开和关闭括号的函数.例如,我总是使用以下功能:
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 [](加载文件"D:\\ work.clj"))
我必须用(ll)来称呼它,但是如果只需要ll,它将很方便.
I have to call this with (ll) but it would come in handy if only ll was needed.
[我的想法来自autocad/autolisp.在这里,我可以定义一个类似(defun c:somecommand()..)
[My idea comes from autocad/autolisp. In there I can define a function like (defun c:somecommand () . . )
从现在开始,我可以在命令行上使用某些命令(因为在命令前使用'c:'.不带括号.)
From this point on I can use somecommand on the commandline (because of 'c:' before the command. Without parentheses.]
推荐答案
可以,但是不应该;)
这是一个示例,滥用(IMHO)进行了覆盖以覆盖 .toString
以产生副作用.
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"]
这篇关于在Repl中使用Clojure而不用打开括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!