小编mis*_*tor的帖子

粘液连接不起作用

我是Emacs和Common Lisp新手.我已经在我的Emacs中成功安装了SLIME,但我无法运行它.Alt+ x slime-connect给出以下选项,接受哪个选项给出了粘贴在选项下面的错误.

Host: 127.0.0.1
Port: 4005

Connecting to Swank on port 4005...
make client process failed: connection refused, :name, SLIME Lisp, :buffer, nil,
                                                :host, 127.0.0.1, :service 4005,
                                                :nowait, nil
Run Code Online (Sandbox Code Playgroud)

我如何让它工作?

lisp emacs common-lisp slime

3
推荐指数
1
解决办法
4479
查看次数

编写此代码的更好方法是什么?

我有以下代码,我觉得它因为重复而臭vi.我怎样才能更好地写出来?

vi = '([a-zA-Z0-9_\-\.]+)'

handlers = [
    (r'/register', RegistrationHandler),
    (r'/profiles/%s/%s' % (vi, vi), GetProfiles),
    (r'/archives/%s/%s/%s/%s' % (vi, vi, vi, vi), GetArchives),
    (r'/publish-profiles', PublishProfiles),
    (r'/publish-bundle/%s/%s' % (vi, vi), PublishBundle),
    (r'/upload-file/%s/%s/%s' % (vi, vi, vi), UploadFile),
    (r"/favicon\.ico", tornado.web.StaticFileHandler, dict(path=settings['static_path'])),
    ]
Run Code Online (Sandbox Code Playgroud)

python idioms

3
推荐指数
2
解决办法
130
查看次数

如何找到与Python中的谓词匹配的序列中的第一个元素?

可能重复:
Python:查找与谓词匹配的序列中的第一个元素

Python标准库中是否有更高阶的函数来封装以下控制流模式?

>>> def find(pred, coll):
...   for x in coll:
...     if pred(x):
...       return x
... 
>>> find(lambda n : n % 2 == 0, [3, 5, 8, 9, 6])
8
>>> find(lambda n : n % 2 == 0, [3, 5, 7, 9, 6])
6
>>> find(lambda n : n % 2 == 0, [3, 5, 7, 9, 1])
Run Code Online (Sandbox Code Playgroud)

python functional-programming python-3.x

3
推荐指数
1
解决办法
3247
查看次数

`ord`实例`on`某些功能

我想Ord为数据类型编写一个实例,该实例Foo将所有比较委托给一个函数bar :: Foo -> Bar,在该函数中Bar有一个Ord实例可用的数据类型.

如果我手动编写此实例,它看起来像:

instance Ord Foo where
  compare x y
    | bar x == bar y = EQ
    | bar x <= bar y = LT
    | otherwise      = GT
Run Code Online (Sandbox Code Playgroud)

有没有更简洁的方式来写这个?


在Scala(使用Scalaz)中,我可以写:

 implicit val FooOrder: Order[Foo] = Order[Bar] contramap bar
Run Code Online (Sandbox Code Playgroud)

Haskell有类似的东西吗?

haskell typeclass

3
推荐指数
1
解决办法
322
查看次数

使用按位运算符检查整数是否为2 ^ 1-2 ^ j的单行

我想要一行代码来检查给定的整数是否为2 i - 2 j或NOT.(使用按位运算符)

language-agnostic bit-manipulation bitwise-operators

2
推荐指数
1
解决办法
267
查看次数

编码字符串C#

我从网上获得了一个页面响应,它有类似的字符串"Lluís Quílez".但我明白了"Llu&#xED;s Qu&#xED;lez".那么如何将其更改回"Lluís Quílez"C#?

谢谢.

c#

2
推荐指数
1
解决办法
3381
查看次数

如何将这个简单的OOP程序转换为函数式编程语言?

在过去的几个月里,我尝试使用函数式编程范例进行编码.现在我有一个OOP解决方案,我正在尝试找到一个功能性解决方案.

问题很简单.我有一个算法,它产生两个不同的数组作为结果(a和b).现在,我想检查结果有多好.因此,我为他们写了几个评估标准.我希望伪java源代码对你没问题!

// first the Algorithm class
class Algorithm {
    private []a;
    private []b;

    Algorithm(input) {
        computeResult();
    }

    getA(){return a;}
    getB(){return b;}

    void computeResult() { 
        ... 
        ... // time-consuming operations 
        ... // set values for a and b
        ...
    }
}

// this class tests the Algorithm using a list of evaluation criteria
class AlgorithmTest {

    AlgorithmTest() {
        ... 
        ... // Definition of input
        ... // Definition of list of evaluation criteria evals
        ...
        Algorithm algorithm = new Algorithm(input); // …
Run Code Online (Sandbox Code Playgroud)

java oop haskell functional-programming clojure

2
推荐指数
1
解决办法
872
查看次数

将列表列表转换为Clojure中列表列表的映射

我有一个列表的列表,并希望进入一个地图,关键是在列表中的共同价值观之一(在这个例子中动物名)这一点.我知道如何使用{}和从列表创建一个地图,但这不是我想要的.我希望地图中的键(动物名称)引用这些值的列表列表.

我已经创建了一个列表列表

(def animals (list '("tiger" "fur" "yellow & black stripes") '("tiger" "weight" "150") '("tiger" "home" "India") '("elephant" "skin" "gray") '("elephant" "weight" "1500") '("elephant" "home" "Africa") '("frog" "skin" "green") '("frog" "diet" "insects")))
Run Code Online (Sandbox Code Playgroud)

动物

(("tiger" "fur" "yellow & black stripes") ("tiger" "weight" "150") ("tiger" "home" "India") ("elephant" "skin" "gray") ("elephant" "weight" "1500") ("elephant" "home" "Africa") ("frog" "skin" "green") ("frog" "diet" "insects"))
Run Code Online (Sandbox Code Playgroud)

这不完全符合我的要求(但差不多)

(def animal-map (into {} (for [[name attribute value] animals] [name (list attribute value)])))
Run Code Online (Sandbox Code Playgroud)

当我想要每个键的多个列表时,这会导致每个键只有一个列表

动物图(列表地图)

{"tiger" ("home" "India"), "elephant" …
Run Code Online (Sandbox Code Playgroud)

maps list clojure

2
推荐指数
1
解决办法
1847
查看次数

为什么我在这里得到"模糊类型变量"错误?

import Data.Monoid

times :: Monoid a => Int -> a -> a
times i = mconcat . replicate i

main =
  print $ times 5 5
Run Code Online (Sandbox Code Playgroud)

此代码提供以下错误:

Ambiguous type variable `a0' in the constraints:
  (Monoid a0) arising from a use of `times'
              at :7:11-15
  (Show a0) arising from a use of `print'
            at :7:3-7
  (Num a0) arising from the literal `5'
           at :7:19
Probable fix: add a type signature that fixes these type variable(s)
In the second argument of `($)', …
Run Code Online (Sandbox Code Playgroud)

haskell functional-programming

2
推荐指数
1
解决办法
156
查看次数

从规范运行单个测试

有没有办法从规范2运行特定的测试Specification?例如,如果我有以下内容:

class FooSpec extends Specification {
  "foo" should {
    "bar" in {
      // ...
    }

    "baz" in {
      // ...
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我想有办法只运行FooSpec > "foo" > "bar"(在这里使用一些任意表示法).

unit-testing scala specs2

2
推荐指数
1
解决办法
291
查看次数