我今天遇到了与SBT的错误.最好用sbt sbt-version命令显示:
运行于5/29/17:
eric@linux-x2vq:~$ sbt sbt-version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option
MaxPermSize=256M; support was removed in 8.0
[info] Set current project to eric (in build file:/home/eric/)
[info] 0.13.13
Run Code Online (Sandbox Code Playgroud)
运行于6/1/17:
eric@linux-x2vq:~$ sbt sbt-version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option
MaxPermSize=256M; support was removed in 8.0
[ERROR] Failed to construct terminal; falling back to unsupported
java.lang.NumberFormatException: For input string: "0x100"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.valueOf(Integer.java:766)
at jline.internal.InfoCmp.parseInfoCmp(InfoCmp.java:59)
at jline.UnixTerminal.parseInfoCmp(UnixTerminal.java:233)
at jline.UnixTerminal.<init>(UnixTerminal.java:64)
at jline.UnixTerminal.<init>(UnixTerminal.java:49)
at …Run Code Online (Sandbox Code Playgroud) 我不是Homebrew专家,但我认为它在2016年9月15日之后的某个时间点已将我从readline版本6.x升级到7.0 :
eat@eric-macbook:Homebrew$ brew info readline
readline: stable 7.0 (bottled) [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/usr/local/Cellar/readline/7.0 (45 files, 2M)
Run Code Online (Sandbox Code Playgroud)
这给我的9.4.5 Homebrew版本的Postgresql带来了麻烦(出于可比性的原因,我需要较旧的9.4):
eat@eric-macbook:~$ psql --version
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/Cellar/postgresql/9.4.5/bin/psql
Reason: image not found
Trace/BPT trap: 5
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法在Homebrew上找到6.x版本的readline来恢复 - 只有7.0似乎可用(?).
我的问题是双重的:
先感谢您!
在完成"从第一原理开始的Haskell编程"时,我对以下问题的答案感到困惑:
如果类型
kessel是(Ord a, Num b) => a -> b -> a,那么类型kessel 1 2是a)
Integer
b)Int
c)a
d)(Num a, Ord a) => a
e)Ord a => a
f)Num a => a
答案是d) - 但我认为答案应该是e),因为第一个参数(a)的类型签名中唯一的要求是它是一个Ord.那么为什么不归来呢?
kessel 'd' 2
Run Code Online (Sandbox Code Playgroud)
是有效的,它是类型Char- 没什么关系Num!
我不明白什么?
谢谢您的帮助.
假设您有 a::givee和 a ::giver:
(s/def ::givee keyword?)
(s/def ::giver keyword?)
Run Code Online (Sandbox Code Playgroud)
形成一个unq/gift-pair:
(s/def :unq/gift-pair (s/keys :req-un [::givee ::giver]))
Run Code Online (Sandbox Code Playgroud)
然后你有一个:unq/gift-historywhich is a vectorof unq/gift-pair:
(s/def :unq/gift-history (s/coll-of :unq/gift-pair :kind vector?))
Run Code Online (Sandbox Code Playgroud)
最后,假设您想替换以下内容:unq/gift-pair之一vector:
(defn set-gift-pair-in-gift-history [g-hist g-year g-pair]
(assoc g-hist g-year g-pair))
(s/fdef set-gift-pair-in-gift-history
:args (s/and (s/cat :g-hist :unq/gift-history
:g-year int?
:g-pair :unq/gift-pair)
#(< (:g-year %) (count (:g-hist %)))
#(> (:g-year %) -1))
:ret :unq/gift-history)
Run Code Online (Sandbox Code Playgroud)
一切正常:
(s/conform :unq/gift-history
(set-gift-pair-in-gift-history [{:givee :me, …Run Code Online (Sandbox Code Playgroud) 以下Elixir代码不正确但传达(我认为)所需的结果:
defmodule Question do
def dbl(n), do: n * 2
def trp(n), do: n * 3
def consumer(xs, f) do
Enum.filter(xs, f.(x) > 5)
end
end
Question.consumer([1, 2, 3], dbl) # [3]
Question.consumer([1, 2, 3], trp) # [2, 3]
Run Code Online (Sandbox Code Playgroud)
应如何consumer方法写入消耗dbl和trp正确?然后你会怎么称呼它?
谢谢!
编辑:
请问相关问题.你会如何在Elixir中编写和调用下面的Scala代码:
def dbl(n: Int): Int = n * 2
def trp(n: Int): Int = n * 3
def consume(xs: List[Int], f: (Int) => Int): List[Int] =
xs.filter(x => f(x) > 5)
consume(List(1, …Run Code Online (Sandbox Code Playgroud) 我正在学习Clojure并享受它,但发现记录中的不一致让我感到困惑:为什么默认的地图构造函数(map-> Whatever)在创建新记录时检查数据完整性?例如:
user=> (defrecord Person [first-name last-name])
#<Class@46ffda99 user.Person>
user=> (map->Person {:first-name "Rich" :last-name "Hickey"})
#user.Person {:first-name "Rich" :last-name "Hickey"}
user=> (map->Person {:first-game "Rich" :last-name "Hickey"})
#user.Person {:first-game "Rich" :first-name nil :last-name "Hickey"}
Run Code Online (Sandbox Code Playgroud)
我相信Map不需要定义Record定义中的所有字段,也允许包含不属于Record定义的额外字段.另外我理解我可以定义自己的构造函数来包装默认构造函数,然后我认为:post可以使用条件来检查正确(和全面)的记录创建(还没有成功地使它工作).
我的问题是:在Map构建记录期间是否有一种惯用的Clojure方法来验证数据?而且,这里有关于唱片的遗漏吗?
谢谢.
我正在尝试在Kotlin中学习函数式编程,并且很难使这段代码工作:
import java.util.*
fun caseName(br: String, c: Int): String {
if (c == 0) {
return br.toLowerCase()
} else {
return br.toUpperCase()
}
}
fun mapIt(ns: ArrayList<String>, f: (String, Int) -> String): List<String> {
val coll: List<String> = ns.map {it -> f(it, _)}
return coll
}
fun main(args: Array<String>) {
val names = arrayListOf("Joe", "Bill", "Murrary")
val cased = mapIt(names, (::caseName)(_, 0))
println(cased.first())
}
Run Code Online (Sandbox Code Playgroud)
mapIt在映射列表时如何识别案例标志?
谢谢!
编辑:上面的案例是以下的简化版本,它不起作用......
data class Borrower(val name: String, val maxBooks: Int) {
companion object { …Run Code Online (Sandbox Code Playgroud) 我在 Kotlin 中有一个简单的书籍和借书人图书馆的模型,如果有借书人,就会借出一本书。我使用 Arrow Option 对借款人的缺席/存在进行编码:
data class Borrower(val name: Name, val maxBooks: MaxBooks)
data class Book(val title: String, val author: String, val borrower: Option<Borrower> = None)
Run Code Online (Sandbox Code Playgroud)
我在 Gson 中将这些对象序列化/反序列化为 JSON 时遇到问题 - 特别是书籍中Option<Borrower>JSON的表示null:
[
{
"title": "Book100",
"author": "Author100",
"borrower": {
"name": "Borrower100",
"maxBooks": 100
}
},
{
"title": "Book200",
"author": "Author200",
"borrower": null
}
]
Run Code Online (Sandbox Code Playgroud)
我的反序列化代码:
fun jsonStringToBooks(jsonString: String): List<Book> {
val gson = Gson()
return try {
gson.fromJson(jsonString, object : TypeToken<List<Book>>() {}.type)
} …Run Code Online (Sandbox Code Playgroud)