本网站提出以下声明:http: //hyperpolyglot.wikidot.com/lisp#ten-primitives
McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, these are the only functions which need to be implemented in a lower language. The way the non-primitives of lisp can be constructed from primitives is analogous to the way theorems can be proven from axioms in mathematics. …
我听说它被称为流,作为一个无限的列表,有时甚至作为一个懒惰的序列.
以下模式的正确用语是什么?(显示的Clojure代码)
(def first$ first)
(defn second$ [str]
(cond
(empty? str) ()
true ((first (rest str)))))
(defn stream-builder [next_ n]
(cons n (cons (fn [] (stream-builder next_ (next_ n))) ())))
(defn stream [str n]
(cond
(= 0 n) ()
true (cons (first$ str) (stream (second$ str) (- n 1)))))
(def odd
(stream-builder (fn [n]
(+ 2 n))1))
(println (stream odd 23))
> (1 3 5 7 9 11 13 15 17 19 …Run Code Online (Sandbox Code Playgroud) 我理解flatMapScala中的等价物是mapcat在Clojure中.
我有一个暗示,mapcat在clojure只适用于序列,不像flatMapScala更灵活.
我的问题是 - 在他们的操作方面,mapcatClojure和flatMapScala 之间有什么区别?
假设:
flatMaps功能的子集.正如我们所知道- core.async 采用 CSP,类似于够程从去浪.现在对于像select和alt 这样的场景来说,这很有道理.
大卫·诺伦在这里做了一个惊人的演示,在Clojure中展示了Clojure中的core.async.
然而,我可以通过简单的for循环复制类似的功能.你可以在这里看到一个演示.
function animationLoop() {
for (var i =0;i<100;i++) {
for (var j= 0; j<100;j++) {
//decision to animate or hold off
var decisionRange = randomInt(0,10);
if (decisionRange < 1) {
var cell = document.getElementById('cell-' + i + j);
cell.innerHTML = randomInt(0,9);
cell.setAttribute('class','group' + randomInt(0,5));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在'10,000进程动画场景'中core.async的实际好处是什么?
我的网站上有一个订单页面.某些订单商品可以包含小数,有些则不能.
防止用户输入小数量的最佳方法是什么?(除了警告框并将字段设置为零)?
查看嵌入式Jetty示例的以下示例:http: //musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html
下面给出了代码示例(如下).
然后,作者继续举例说明在web.xml文件中引用上下文参数.例如
...
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
...
Run Code Online (Sandbox Code Playgroud)
我的问题是 - 如果我想在Java类中做所有事情 - 有没有办法以编程方式设置context-params?
public class JettyRunner {
public static void main(String[] args) throws Exception {
Server server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
connector.setHost("127.0.0.1");
server.addConnector(connector);
WebAppContext wac = new AliasEnhancedWebAppContext();
wac.setContextPath("/myapp");
wac.setBaseResource(
new ResourceCollection(
new String[] {"./src/main/webapp", "./target"}));
wac.setResourceAlias("/WEB-INF/classes/", "/classes/");
server.setHandler(wac);
server.setStopAtShutdown(true);
server.start();
server.join();
}
}
Run Code Online (Sandbox Code Playgroud) 这是一个诚实的问题,而不是一个巨魔.我请你耐心等待.
当Cedric谈到依赖类型时,他声明的好处是在编译时检查List长度:
拥有一个包含一个元素的列表将是一个类型错误,因此上面代码段中的第二行不应该编译.
当Ana Bove和Peter Dybjer谈论依赖类型时,他们声明的好处是在编译时检查列表长度:
依赖类型是依赖于其他类型元素的类型.一个例子是长度为n且具有类型A的分量的向量的类型An.另一个例子是m个n矩阵的Amn类型.我们说类型An取决于数字n,或者An是由数字n索引的类型族.
更重要的是,由于在编译时有额外的信息和检查,我们对程序的正确性有额外的保证.
现在我的经验是,人们(来自Haskell背景)嘲笑Lisp,因为它是一种"动态语言".他们来自哪里是因为它与丰富的Haskell类型系统相比它看起来不健全.(我没有反对他们 - 我认为这很有趣).
关键是他们声称Haskell(或Agda等)在编译时有额外的信息,这些信息对于像Lisp这样的动态语言是不可用的.(我将使用Lisp作为'语言家族'并假设Clojure是一个Lisp).
现在,我可以在Clojure中执行以下操作,以在编译时检查数组的长度:
(def my-vec-of-length-2 [0 1])
(defmacro compile-time-vec-length-check [x n]
(let [x @(resolve x)]
(assert (= n (count x)))))
(compile-time-vec-length-check my-vec-of-length-2 3)
Run Code Online (Sandbox Code Playgroud)
现在这将失败,因为我期待一个长度为3的向量,但底层向量的长度为2.我在编译时得到了这个信息.
user$ lein uberjar
Compiling compile-time-vec-check.core
Exception in thread "main" java.lang.AssertionError: Assert failed: (= n (count x))
Run Code Online (Sandbox Code Playgroud)
现在,我似乎在"动态语言"中获得了Dependent Typing的好处.
我的问题是,是否有可能在Lisp中实现使用宏的依赖键入的好处?
这是关于Clojure与其他语言(如Haskell)的表现力的问题.更广泛的问题是表达问题的解决方案
这个问题得出的结论是,一般来说Clojure协议(和多方法)的表达力要低于Haskell类型类,因为协议在第一个参数上调度,而Haskell类型类可以在返回类型上调度.(现在我认为这种推理非常有趣,并且没有兴趣开始语言大战.我只是对思想的清晰度感兴趣).
作为打破这种推理的一部分 - 我的问题是 - 我们不能制作一个Clojure多方法来调度返回类型(或类型提示).我想我们可以将以下表达式放入Clojure多方法中:
(= java.lang.String (:tag (meta #'my-string)))
Run Code Online (Sandbox Code Playgroud)
功能是:
(defn ^String my-string []
"hello world")
Run Code Online (Sandbox Code Playgroud)
编辑:关键是我可以运行:
(meta #'my-string)
Run Code Online (Sandbox Code Playgroud)
并在没有功能评估的情况下获得以下结果:
{:arglists ([]), :ns #<Namespace push-price.core>, :name my-string, :column 1,
:line 1, :file "/private/var/folders/0l/x6hr0t1j2hvcmm_sqq04vdym0000gn/T/form-
init7576840885484540032.clj", :tag java.lang.String}
Run Code Online (Sandbox Code Playgroud)
即我没有评估我的功能的预期类型的一些信息.
编辑3(2014年4月24日):
假设我有以下类型:(deftype string-type [])
(deftype int-type [])
Run Code Online (Sandbox Code Playgroud)
然后我根据这些类型定义了以下函数:
(defn #^{:return-type string-type} return-string []
"I am returning a string")
(defn #^{:return-type int-type} return-int []
42)
Run Code Online (Sandbox Code Playgroud)
现在我编写一个函数来调度它们的返回类型,如下所示:
(defn return-type-dispatch [fn-arg]
(let [return-type (:return-type (meta fn-arg))]
(cond
(= return-type …Run Code Online (Sandbox Code Playgroud) 在她的演讲中,Clojure Bodil 的未来提出以下主张:
盖伊斯蒂尔在ICFP上发表了一篇名为" 组织并行执行功能代码"(或者,折叠和折叠考虑稍微有害)的演讲(同样在ACM中).
其中盖伊斯蒂尔在幻灯片70中断言:
一旦你说"第一次
SUM = 0",你就被冲洗了.对于并行性,累加器是不可靠的.请注意,foldl和foldr,虽然功能,从根本上累积.
这有点有趣.所以Bodil说Guy Steele正在呼唤一个问题.然后她声称Rich用Reducers(以及Transducers,它是这种思路的延续)来解决它.在16:11 的Transducers演讲中,我们看到Rich发表了一些特别的论文foldr.
Rich有效地说folds是可组合的 - 你可以用它们来构建其他更高阶的函数,比如map和filter.
我的问题是 - 博迪尔对吗?Rich有没有解决Guy Steele设置的问题?减速器(在Clojure中)是否解决了Guy Steele概述的缩放倍数累积问题?
假设这是一台Windows 7机器 - 我们正在谈论Windows命令行上的批处理脚本.
想象一下,我想启动和停止在后台运行的两个不同进程,并在后台运行时运行.例如:
START /B CMD /C tomcatA.bat
doSomeStuff
stopTomcatACmd
START /B CMD /C tomcatB.bat
doSomeStuff
stopTomcatBCmd
Run Code Online (Sandbox Code Playgroud)
我正在试图弄清楚如何实现stopTomcatBCmd.在Linux计算机上你可以只kill的pid.
我的问题是:如何杀死Windows中后台运行的特定进程?
clojure ×7
haskell ×2
lisp ×2
batch-file ×1
cmd ×1
compile-time ×1
core.async ×1
decimal ×1
fold ×1
function ×1
goroutine ×1
html ×1
java ×1
javascript ×1
kill ×1
macros ×1
multimethod ×1
predicate ×1
reducers ×1
scala ×1
sequence ×1
terminology ×1
typeclass ×1
types ×1
web-testing ×1
windows ×1