小编haw*_*eye的帖子

你能用十个原语实现任何纯LISP函数吗?(即没有类型谓词)

本网站提出以下声明: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. …

lisp types predicate function clojure

10
推荐指数
1
解决办法
1370
查看次数

以下函数式编程模式的正确术语是什么?

我听说它被称为,作为一个无限的列表,有时甚至作为一个懒惰的序列.

以下模式的正确用语是什么?(显示的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)

lisp functional-programming terminology clojure sequence

10
推荐指数
2
解决办法
728
查看次数

在Clojure中的mapcat和Scala中的flatMap之间的区别是什么?

我理解flatMapScala中的等价物是mapcat在Clojure中.

我有一个暗示,mapcat在clojure只适用于序列,不像flatMapScala更灵活.

我的问题是 - 在他们的操作方面,mapcatClojure和flatMapScala 之间有什么区别?

假设:

  • 据我所知,Scala有一个丰富的类型系统,而Clojure有可选的输入 - 我很想知道mapcat接受的参数是否有限制,这使得它只有flatMaps功能的子集.

scala clojure

10
推荐指数
2
解决办法
4675
查看次数

core.async和10,000个动画过程 - 这种情况下的实际好处是什么?

正如我们所知道- 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的实际好处什么?

clojure goroutine clojurescript core.async

10
推荐指数
1
解决办法
794
查看次数

如何防止用户输入小数?

我的网站上有一个订单页面.某些订单商品可以包含小数,有些则不能.

防止用户输入小数量的最佳方法是什么?(除了警告框并将字段设置为零)?

html javascript decimal

9
推荐指数
1
解决办法
1万
查看次数

有没有办法在嵌入式码头中以编程方式设置context-params?

查看嵌入式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)

java web-testing embedded-jetty

9
推荐指数
1
解决办法
4330
查看次数

是否有可能在Lisp中使用宏来实现依赖键入的好处?

这是一个诚实的问题,而不是一个巨魔.我请你耐心等待.

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中实现使用宏的依赖键入的好处?

macros haskell clojure compile-time dependent-type

9
推荐指数
1
解决办法
1080
查看次数

Clojure - 返回类型的派遣?(与Haskell Typeclasses一样富有表现力)

这是关于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)

haskell clojure typeclass multimethod clojure-protocol

9
推荐指数
1
解决办法
564
查看次数

减速器(在Clojure中)是否解决了Guy Steele概述的缩放倍数累积问题?

在她的演讲中,Clojure Bodil 的未来提出以下主张:

盖伊斯蒂尔在ICFP上发表了一篇名为" 组织并行执行功能代码"(或者,折叠和折叠考虑稍微有害)的演讲(同样在ACM中).

其中盖伊斯蒂尔在幻灯片70中断言:

一旦你说"第一次SUM = 0",你就被冲洗了.对于并行性,累加器是不可靠的.请注意,foldlfoldr,虽然功能,从根本上累积.

这有点有趣.所以Bodil说Guy Steele正在呼唤一个问题.然后她声称Rich用Reducers(以及Transducers,它是这种思路的延续)来解决它.在16:11 的Transducers演讲中,我们看到Rich发表了一些特别的论文foldr.

Rich有效地说folds是可组合的 - 你可以用它们来构建其他更高阶的函数,比如mapfilter.

我的问题是 - 博迪尔对吗?Rich有没有解决Guy Steele设置的问题?减速器(在Clojure中)是否解决了Guy Steele概述的缩放倍数累积问题?

parallel-processing clojure fold reducers

9
推荐指数
1
解决办法
284
查看次数

如何从命令提示符处杀死在后台运行的特定进程?

假设这是一台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计算机上你可以只killpid.

我的问题是:如何杀死Windows中后台运行的特定进程?

windows cmd kill batch-file

9
推荐指数
1
解决办法
1万
查看次数