我是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)
我如何让它工作?
我有以下代码,我觉得它因为重复而臭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:查找与谓词匹配的序列中的第一个元素
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) 我想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有类似的东西吗?
我想要一行代码来检查给定的整数是否为2 i - 2 j或NOT.(使用按位运算符)
我从网上获得了一个页面响应,它有类似的字符串"Lluís Quílez".但我明白了"Lluís Quílez".那么如何将其更改回"Lluís Quílez"C#?
谢谢.
在过去的几个月里,我尝试使用函数式编程范例进行编码.现在我有一个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) 我有一个列表的列表,并希望进入一个地图,关键是在列表中的共同价值观之一(在这个例子中动物名)这一点.我知道如何使用{}和从列表创建一个地图,但这不是我想要的.我希望地图中的键(动物名称)引用这些值的列表列表.
我已经创建了一个列表列表
(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) 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) 有没有办法从规范2运行特定的测试Specification?例如,如果我有以下内容:
class FooSpec extends Specification {
"foo" should {
"bar" in {
// ...
}
"baz" in {
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想有办法只运行FooSpec > "foo" > "bar"(在这里使用一些任意表示法).