我正在为 RethinkDB使用Clojure 驱动程序。我想从查询中获取更改提要。这是我到目前为止所拥有的:
(defn change-feed [conn]
(loop [changes (future
(-> (r/db "mydb")
(r/table "mytable")
r/changes
(r/run conn)))]
(println "date : " ((comp :name :newval) first @changes)) ;;prints nil
(recur (rest changes))))
Run Code Online (Sandbox Code Playgroud)
它在调用时阻塞在我的 REPL 中(这是正常的)。然后我使用 RethinkDB 接口添加数据。它打印nil,我收到以下错误:
IllegalArgumentException Don't know how to create ISeq from: clojure.core$future_call$reify__6736 clojure.lang.RT.seqFrom (RT.java:528)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 ?我希望能够:
注意:我打算最终使用manifold来操纵结果,因此任何使用它的解决方案都完全没问题。
阅读此问题后,从用户数据创建Clojure关键字的安全隐患?,特别是这个答案,我试图找到一个案例,我可以在REPL中证明这个问题.这是一个尝试:
user> *clojure-version*
{:major 1, :minor 8, :incremental 0, :qualifier nil}
user> (def a (atom 0))
#'user/a
user> (defn bad-fn []
(println "called ")
(swap! a inc))
#'user/bad-fn
user> @a
0
user> (keyword "#=(bad-fn)")
:#=(bad-fn)
user> @a
0
Run Code Online (Sandbox Code Playgroud)
我该如何重现这个问题?
我在Clojure中包装了一个日志库; 让我们调用它的命名空间foo.logger.现在我有另一个命名空间bar.baz,从那里我称之为记录器.
是否有一些惯用/好的方式,我可以确定记录器内的调用者命名空间的命名空间?我不想将此设置为记录器的参数;-)
使用Clojure let以下列方式嵌套是好的做法,还是令人困惑?
(defn a-fun [config]
(let [config (-> config (parse) (supply-defaults))]
;; do something with config
))
Run Code Online (Sandbox Code Playgroud)
我注意到我在输入函数中经常解析/检查/验证事物的模式与外部世界交互(在这种情况下是一个暴露公共函数的Clojurescript库,但我也有同样感觉的Compojure路径).
是否令人困惑,因为必须了解绑定可见性的规则(不确定具体的措辞是什么)?
这样做的惯用方法是什么?将config名称更改为parsed-config,将其放在另一个函数中,完全是其他内容吗?
测试ClojureScript中是否存在某些内容的方法是什么?例如,我正在尝试访问浏览器地理位置API.在javascript中,我会做一个简单的检查:
// check for Geolocation support
if (navigator.geolocation) {
console.log('Geolocation is supported!');
}
else {
console.log('Geolocation is not supported for this Browser/OS version yet.');
}
Run Code Online (Sandbox Code Playgroud)
但是将它翻译成ClojureScript,我收到一个错误:
(if (js/navigator.geolocation) ;; Uncaught TypeError: navigator.geolocation is not a function
(println "Geolocation is supported")
(println "Geolocation is not supported"))
Run Code Online (Sandbox Code Playgroud)
在ClojureScript中检查浏览器功能的正确方法是什么?
我想将assoc地图的值添加到atom.我可以这样做:
(defonce config (atom {}))
(swap! config assoc :a "Aaa")
(swap! config assoc :b "Bbb")
Run Code Online (Sandbox Code Playgroud)
但这是重复的,并拨打了几个电话swap!.我想做那样的事情:
(swap! config assoc {:a "Aaa"
:b "Bbb"})
;; this doesn't work :
;; Exception in thread "main" clojure.lang.ArityException: Wrong number of args (2) passed to: core$assoc
Run Code Online (Sandbox Code Playgroud)
我怎么做 ?
I want to set the require-final-newline for every buffer to nil.
In my config file, I have :
(setq require-final-newline nil)
(setq-default require-final-newline nil)
Run Code Online (Sandbox Code Playgroud)
It appears to set the global value correctly. However in every buffer that I open, the local value is still t. Using describe-variable, I get :
require-final-newline is a variable defined in `files.el'.
Its value is t
Original value was nil
Local in buffer myfile.js; global value is nil
Run Code Online (Sandbox Code Playgroud)
files.el is in /usr/local/Cellar/emacs/24.5/share/emacs/24.5/lisp/ …
Java Nashorn是否支持JavaScript 模板字符串?
尝试时出现以下错误var a = `this is a \n multiline string \n `:
javax.script.ScriptException: <eval>:1:22 Expected an operand but found error
有没有办法避免重复1使用以下行cl-format?
(cl-format true "line~p: ~d\n" 1 1)
我正在使用多方法提供不同的功能,具体取决于我的项目运行的"模式"(它是一个yada api服务器,应该能够运行:dev,:prod模式等).
我正在使用mount/defstate提供关键字:
(defstate mode :start :dev)
Run Code Online (Sandbox Code Playgroud)
当我发送使用时(constantly mode),我得到错误但是当我使用(fn [& _] mode)它发送时似乎工作.
这两种形式不一样吗?或者评估它们的方式(或时间)是否存在细微差别?
clojure ×7
asynchronous ×1
atomic ×1
common-lisp ×1
emacs ×1
emacs24 ×1
java ×1
logging ×1
namespaces ×1
nashorn ×1
rethinkdb ×1
security ×1