有没有人知道Clojure的一个好的分析工具或库?
我更喜欢可以在REPL中使用的东西,就像(with-profiling ...)Allegro Common Lisp那样.
沿着这些路线还有什么吗?
或者您对使用Clojure的(非商业)Java分析器有任何经验吗?
我正在尝试使用Clojure 1.2,特别是deftype根据clojure.org文档支持的可变字段.
但是我不能让这套装置工作.更新字段的语法是什么?或者是否实现了可变性?
(definterface IPoint
(getX [])
(setX [v]))
(deftype Point [x]
IPoint
(getX [this] x)
(setX [this v] (set! (.x this) v)))
user=> (def p (Point. 10))
user=> (.getX p)
10
user=> (.setX p 20)
ClassCastException: user.Point cannot be cast to compile__stub.user.Point
Run Code Online (Sandbox Code Playgroud)
使用几天前的1.2快照.
我不确定这是属于StackOverflow还是属于Clojure Google小组.但该小组似乎正在忙着讨论Clojure 1.2的数字改进,所以我会在这里尝试:
http://shootout.alioth.debian.org/为各种语言提供了许多性能基准.
我注意到Clojure丢失了,所以我制作了一个关于n体问题的Clojure版本.
我可以在这里找到我能够生成的最快的代码,并且对它进行基准测试似乎是说数字运算Clojure是
我对这种性能表现非常满意.
我对Clojure大师的问题是
更新
对于枪战更多的Clojure 1.1基准程序在这里,其中包括正体问题.
我觉得这里有点傻,但是我无法编译Clojure Hello World.
目录结构:
hello-world/
clojure-1.1.0.jar
build/
classes/
src/
test/
hello.clj
Run Code Online (Sandbox Code Playgroud)
hello.clj:
(ns test.hello
(:gen-class))
(defn -main [& args]
(println "Hello" (nth args 0)))
Run Code Online (Sandbox Code Playgroud)
相互作用:
$ cd hello-world
[hello-world]$ java -cp ./clojure-1.1.0.jar:./build/classes:./src clojure.main
Clojure 1.1.0
user=> (require 'test.hello)
nil
user=> (test.hello/-main "there")
Hello there
nil
user=> (compile 'test.hello)
java.io.IOException: No such file or directory (hello.clj:2)
user=> *compile-path*
"classes"
user=> (doseq [p (.split (System/getProperty "java.class.path") ":")] (println p))
./clojure-1.1.0.jar
./build/classes
./src
nil
Run Code Online (Sandbox Code Playgroud)
所以我可以从REPL加载并调用该文件,但它不能编译.
根据clojure.org,编译需要
在定义结构类型和实例时,我可以打印该值并获取"struct"实现类型:
(defstruct person :name :age)
(def p (struct person "peter" 30))
user=> p
{:name "peter", :age 30}
user=> (type p)
clojure.lang.PersistentStructMap
Run Code Online (Sandbox Code Playgroud)
但是有可能判断p是否是结构类型"人"的实例?
我有一台本地机器("笔记本电脑")和另一台机器("服务器")上的共享Mercurial存储库.
共享存储库设置为多存储库,如Mercurial文档中所述,使用Apache,hgwebdir.cgi脚本和Mercurial 1.4.
设置工作的意义是我可以浏览Web浏览器中的项目(存储库),我可以从服务器克隆和拉出,当服务器上已存在项目/存储库时,我可以从笔记本电脑推送.
但我不能在笔记本电脑上创建一个新项目(hg init,做东西,hg commit)并将其推送到共享多存储库(hg push http:// server/hg/my-new-project-name) - I得到"中止:HTTP错误404:未找到",可能是因为目录/项目存储库尚不存在.
如何将新项目/目录结构推送到其他地方运行的Mercurial?我在文档中找不到任何内容,你们是怎么做到的?
我有几天学习Clojure并且有一些出牙问题,所以我在寻求建议.
我正在尝试将一个Java类存储在Clojure var中并调用其静态方法,但它不起作用.
例:
user=> (. java.lang.reflect.Modifier isPrivate 1)
false
user=> (def jmod java.lang.reflect.Modifier)
#'user/jmod
user=> (. jmod isPrivate 1)
java.lang.IllegalArgumentException: No matching method found: isPrivate for class java.lang.Class (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4543)
Run Code Online (Sandbox Code Playgroud)
从异常看起来,运行时期望var保存一个对象,因此它调用.getClass()来获取类并使用反射查找方法.在这种情况下,var已经拥有一个类,因此.getClass()返回java.lang.Class并且方法查找显然失败.
除了编写我自己的宏之外,还有什么方法吗?
在一般情况下,我想在varible中拥有一个对象或一个类,并在其上调用适当的方法 - 为静态方法和实例方法打字.
在这个特定的情况下,我只想更短的名字java.lang.reflect.Modifier,如果你愿意的别名.我知道import,但寻找更通用的东西,比如Clojure名称空间别名,但是对于Java类.还有其他机制吗?
编辑:
也许我只是对这里的调用约定感到困惑.我认为Lisp(以及扩展Clojure)模型是评估所有参数并将列表中的第一个元素称为函数.
在这种情况下(= jmod java.lang.reflect.Modifier)返回true,(.getName jmod)并且(.getName java.lang.reflect.Modifier)都返回相同的字符串.
因此变量和类名明确地评估为相同的东西,但它们仍然不能以相同的方式被调用.这里发生了什么?
编辑2
回答我的第二个问题(这里发生了什么),Clojure文档说明了这一点
如果第一个操作数是解析为类名的符号,则该访问被视为指定类的静态成员...否则,它被假定为实例成员
http://clojure.org/java_interop在"The Dot special form"下
"解析为类名"显然与"评估解析为类名的东西"不同,所以我在这里尝试做的并不是点特殊形式所支持的.
我正在寻找一种惯用的方法来获取Clojure中的动态范围变量(或类似的效果),以便在模板等中使用.
以下是使用查找表将标记属性从某些非HTML格式转换为HTML的示例问题,其中表需要访问从其他位置提供的一组变量:
(def *attr-table*
; Key: [attr-key tag-name] or [boolean-function]
; Value: [attr-key attr-value] (empty array to ignore)
; Context: Variables "tagname", "akey", "aval"
'(
; translate :LINK attribute in <a> to :href
[:LINK "a"] [:href aval]
; translate :LINK attribute in <img> to :src
[:LINK "img"] [:src aval]
; throw exception if :LINK attribute in any other tag
[:LINK] (throw (RuntimeException. (str "No match for " tagname)))
; ... more rules
; ignore string keys, used for internal bookkeeping …Run Code Online (Sandbox Code Playgroud) clojure ×7
benchmarking ×1
compilation ×1
deftype ×1
mercurial ×1
performance ×1
profiling ×1
struct ×1