在Clojure到达现场之前,JVM已经有三个Lisps:Kawa,Armed Bear和SISC.
那些Lisps留下的Clojure填补了什么空白?
def foo
f = Proc.new { return "return from foo from inside proc" }
f.call # control leaves foo here
return "return from foo"
end
def bar
b = Proc.new { "return from bar from inside proc" }
b.call # control leaves bar here
return "return from bar"
end
puts foo # prints "return from foo from inside proc"
puts bar # prints "return from bar"
Run Code Online (Sandbox Code Playgroud)
我认为这个return关键字在Ruby中是可选的,return无论你是否请求它,你总是在想.鉴于这种情况,我觉得很奇怪,foo并bar有不同的输出由事实来确定foo包含一个明确的return在Proc …
如果我想学习Clojure,我应该从学习Scheme或Common Lisp开始吗?
或者Clojure与这两者有什么不同,我应该开始自己学习Clojure?
如果用instance_eval定义Foo,有什么区别吗:..
class Foo
def initialize(&block)
instance_eval(&block) if block_given?
end
end
Run Code Online (Sandbox Code Playgroud)
...或者'屈服自我':
class Foo
def initialize
yield self if block_given?
end
end
Run Code Online (Sandbox Code Playgroud)
无论哪种情况,您都可以这样做:
x = Foo.new { def foo; 'foo'; end }
x.foo
Run Code Online (Sandbox Code Playgroud)
所以' yield self'意味着Foo.new之后的块总是在Foo类的上下文中进行评估.
它是否正确?
我把它键入Clojure REPL(使用enclojure Netbeans插件):
user=> "hello, world"
"hello, world"
nil
Run Code Online (Sandbox Code Playgroud)
什么是零?
比方说,我创建两个banches 在同一时间:
hg branch branch-A
hg branch branch-B
Run Code Online (Sandbox Code Playgroud)
如何将我的下一次提交发送到branch-A而不是branch-B?
根据这篇文章,要求rubygems是一个反模式.
require 'rubygems'
Run Code Online (Sandbox Code Playgroud)
这个论点似乎归结为:
当我使用你的库,部署你的应用程序,或运行你的测试我可能不想使用rubygems.当您在代码中需要"rubygems"时,您将无法做出决定.我不能不要求rubygems,但你不能首先要求它.
但是,当您与其他人一起创建和共享代码库时,您所要求的任何Ruby库都无法进行相同的论证吗?
def any?
if block_given?
method_missing(:any?) { |*block_args| yield(*block_args) }
else
!empty?
end
end
Run Code Online (Sandbox Code Playgroud)
在ActiveRecord的代码中,块中存在的yield语句的目的是什么?
我是Mercurial的新手,我开始意识到我的基本工作流程可能不是最有效的工作方式,因为我经常执行提交,而且功能改进非常小,以至于我需要更早地找到一些步骤恢复,这是非常困难的.
这是我在Mercurial中设置项目并完成第一次提交后所做的事情.
hg commit -m "improvement A works"hg commit -m "improvement B works"hg commit -m "feature A works"如果我发现"改进A"中出现了错误,我打开历史记录(使用Netbeans Mercurial可视插件)并将一些代码复制并粘贴回我当前版本并从那里重新开始.
这似乎不是一个好的系统 - 我会很感激任何建议.
如果我创建一个分支:
hg branch branch-A
Run Code Online (Sandbox Code Playgroud)
并承诺:
hg commit -m "improvement A-1"
Run Code Online (Sandbox Code Playgroud)
然后创建第二个分支:
hg branch branch-B
Run Code Online (Sandbox Code Playgroud)
并承诺:
hg commit -m "improvement B-1"
Run Code Online (Sandbox Code Playgroud)
如果我想将我的下一个更改添加到branch-A,我只需输入:
hg branch branch-A
Run Code Online (Sandbox Code Playgroud)
像以前一样承诺:
hg commit -m "improvement A-2"
Run Code Online (Sandbox Code Playgroud)