在查看其他人的Clojure代码时,我偶尔会看到一个定义的函数defn,然后使用var-quote语法调用,例如:
user> (defn a [] 1)
#'user/a
user> (a) ; This is how you normally call a function
1
user> (#'a) ; This uses the var-quote syntax and produces the same result
1
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我无法弄清楚这两种调用函数的方式之间的区别.我在评估文档中找不到任何内容来说明当调用的操作符是var时会发生什么,这可能表明为什么第二种形式是首选的.他们似乎都对binding作业和语法引用作出了相同的回应.
那么,能不能请人提供一个代码示例,将说明之间的区别(a)和(#'a)上面?
编辑:我知道var-quote可以用于获取被let词法绑定所遮蔽的var ,但在我正在查看的代码中似乎并非如此.
当传递的参数是文字时,一个类型提示函数如何调用函数调用nil?我遇到了一种情况,我试图用多个单参数构造函数代理Java类,例如:
public class MyClass {
public MyClass(String a) {...}
public MyClass(List b) {...}
}
Run Code Online (Sandbox Code Playgroud)
我想调用为我的代理接受字符串参数的构造函数,但是为该参数传递一个null值.只需致电:
(proxy [MyClass] [nil] ...)
Run Code Online (Sandbox Code Playgroud)
抛出一个异常,因为Clojure找到了多个构造函数,并且不知道要调用哪个构造函数.但是尝试添加类型提示,如下所示:
(proxy [MyClass] [^String nil] ...)
Run Code Online (Sandbox Code Playgroud)
使用"元数据只能应用于IMetas"消息抛出异常.足够公平 - 在阅读nil文字时,读者无需附加元数据.那么我该如何解决这个问题呢?我能够提出一个涉及的解决方案let,但它似乎相当kludgy:
(let [NIL! nil]
(proxy [MyClass] [^String NIL!] ...))
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
我想利用Clojure 的HDF5 java库.不幸的是,通常的方式包括java依赖(即通过Leiningen对Maven存储库的支持)是不可用的.这可能是因为HDF5-Java库是一组JNI包装的已编译C++和Fortran代码.
我看了Maven-izing最近版本的HDF5-Java,但是不明白平台特定版本是如何在那里处理的/决定了太多的痛苦.假设我坚持使用由HDF集团发布的特定于平台的罐子,是否有一种相对较好的方法来处理这些,同时继续大多生活在Leiningen的舒适世界中?
我目前想知道是否有一种equals在Java 中实现非静态内部类的方法的好方法.我基本上是Foo一个Bar像这样的内部类的类:
public class Foo {
private final String foo; // constructor omitted
public /* non-static */ class Bar {
private final String bar; // constructor omitted
@Override
public boolean equals(Object other) {
return other != null && other.getClass() == getClass()
&& ((Bar) other).bar.equals(this.bar)
&& Foo.this.equals(Foo.((Bar) other)); // Will, of course, not compile.
}
}
@Override
public boolean equals(Object other) {
return other != null && other.getClass() == getClass()
&& ((Foo) other).foo.equals(foo);
}
} …Run Code Online (Sandbox Code Playgroud) 在树结构中,如何将键/值与每个分支合并,其中值是分支值和所有父分支值的总和?
例如,从跟随树结构开始:
[{ :v 1
:_ [{ :v 2 }
{ :v 3
:_ [{ :v 5 }]}
{ :v 4 }]}]
Run Code Online (Sandbox Code Playgroud)
怎么可以重建为:
[{ :v 1
:sum 1
:_ [{ :v 2
:sum 3 }
{ :v 3
:sum 4
:_ [{ :v 5
:sum 9 }]}
{ :v 4
:sum 5 }]}]
Run Code Online (Sandbox Code Playgroud)
我一直在努力walk.我认为这可能是正确的做法.但是,到目前为止我还没有管理它.
我正在使用JQuery制作一个非常基本的动画.基本上我所拥有的是DIV,其宽度为60%,高度为80%,并且包含手册.我的目标是,当您浏览手册中的页面时,当前页面会向上移动并消失,下一页从底部开始.
我足够接近,但有些事情是错的,我无法理解如何解决它 - 页面DIV在容器外可见.他们的顶级财产设定为110%但我可以看到它没有生效.他们的位置只受上面菜单表的影响.
所以我的问题,实际上是 - 如何在容器外部使DIV不可见,但不改变整个DIV的可见性或显示,所以在向上移动时会看到文本 - 但只有放在容器上的文本和不在它之外.
.manualPage {
color:rgba(241, 241, 241,1.0);
top:110%;
text-align:left;
left:0%;
cursor:default;
z-index:30;
font-family: "Open Sans", sans-serif;
font-size:11pt;
width:100%;
height:100%;
}
.BigWindow {
position:absolute;
width:60%;
height:80%;
top:10%;
display:inline-block;
left:-70%;
background-repeat:repeat;
color:rgba(241, 241, 241,1.0);
font-family: "Open Sans", sans-serif;
font-size:12pt;
text-align:center;
cursor:default;
z-index:30;
}
Run Code Online (Sandbox Code Playgroud)
注意BigWindow是容器,manualPage是页面.
这是函数,但我认为CSS问题是首先要解决的问题:
var currentPage = -1;
function setManualPage(num) {
if ($('#manualMenu').css('display') != 'none')
$('#manualMenu').fadeOut(750);
if (currentPage != -1) {
$('#page' + currentPage).animate({ top: '-100%' }, screen.availHeight / 2, function () { $('#page' …Run Code Online (Sandbox Code Playgroud)