我猜想之间的差别delimited,并undelimited延续像之间的差异call和jump.
如果我们调用delimitedcontinuation,它将在完成后返回给调用者.如果我们调用undelimitedcontinuation,它就会工作,goto并且永远不会返回给调用者.
是否有意义?我错过了什么吗?
language-agnostic continuations programming-languages functional-programming
假设我有一个数字列表.如何将列表转换为其"增量"列表 - 后续数字的成对差异?
例如:鉴于List(5, 2, 1, 1)我想得到List(3, 1, 0)
我定义了一个返回Fibonacci流的函数,如下所示:
def fib:Stream[Int] = {
Stream.cons(1,
Stream.cons(2,
(fib zip fib.tail) map {case (x, y) => println("%s + %s".format(x, y)); x + y}))
}
功能正常但看起来效率低(参见下面的输出)
scala> fib take 5 foreach println 1 2 1 + 2 3 1 + 2 2 + 3 5 1 + 2 1 + 2 2 + 3 3 + 5 8
所以,看起来该函数从一开始就计算出第n个斐波纳契数.这是对的吗?你会怎么解决它?
我在REPL中尝试了以下内容:
scala> null.asInstanceOf[Int] res12: Int = 0 scala> null.asInstanceOf[Float] res13: Float = 0.0 scala> null.asInstanceOf[Double] res14: Double = 0.0
在这种情况下,它会期望运行时异常(NPE或ClassCastException).
有人可以解释为什么 Scala会null归零吗?
我moment.js用来格式化人类可读格式的持续时间.
例如(d是一个Date对象):
moment(d).subtract("days", 3).from(d) // returns "3 days ago"
现在我想"2周前",但下面的代码会返回以天为单位的持续时间
moment(d).subtract("weeks", 2).from(d) // returns "14 days ago" i/o "2 weeks ago"
如何"2周前"获得moment.js?
函数eventloop在Scala Actors中做了什么以及它对什么有用?
实现以下示例的最佳方法是什么?
Actor server接收Requests,处理它们,Response
为每个创建一个新的Request并将其发送Response回Request发送方.
演员client发送Requests和接收Responses.
所有这些通信都是异步的,因此它使用react.
这只是一个例子,所以它不应该处理所有这些情况,如server下降,client卡住等.它应该只是简洁和富有表现力.
假设我必须可爱的几个CPU绑定任务.例如,如果我有4个CPU,我可能会创建一个4-5个工作线程的固定大小的线程池,等待队列并将任务放入队列中.在Java中,我可以使用java.util.concurrent(可能ThreadPoolExecutor)实现此机制.
你会如何用Scala演员实现它?
假设我改变了文件foo.txt并运行git add foo.txt.现在foo.txt出现在"要提交的更改"列表中.
现在我想foo.txt 在这些变化之前看到我.我怎么能这样做git?
假设,我有一份清单Students.Students有像田name,birth date,grade等你将如何找到Students最好的grade斯卡拉?
例如:
List(Student("Mike", "A"), Student("Pete", "B"), Student("Paul", A))"
我想得到
List(Student("Mike", "A"), Student("Paul", A))
显然,我可以找到max grade(上面列表中的"A")然后filter列表
students.filter(_.grade == max_grade)
此解决方案仅O(N)在列表上运行两次.你能提出更好的解决方案吗?
scala ×7
actor ×3
casting ×1
concurrency ×1
fibonacci ×1
git ×1
javascript ×1
momentjs ×1
null ×1
stream ×1