小编Łuk*_*Lew的帖子

双变量参数列表

我需要这样的东西:

class Node (left : Node*, right : Node*)
Run Code Online (Sandbox Code Playgroud)

我理解这个签名的模糊性.

有没有办法比以下更好?

class Node (left : Array[Node, right : Array[Node])
val n = new Node (Array(n1, n2), Array(n3))
Run Code Online (Sandbox Code Playgroud)

也许是这样的某种分隔符?

val n = new Node (n1, n2, Sep, n3)
Run Code Online (Sandbox Code Playgroud)

scala variadic-functions scala-2.8

4
推荐指数
2
解决办法
539
查看次数

如何在Scala中获取Ponter/Reference语义

在C++中,我只需要指向arr [idx]的指针(或引用).
在Scala中,我发现自己创建了这个类来模拟指针语义.

class SetTo (val arr : Array[Double], val idx : Int) {
  def apply (d : Double) { arr(idx) = d }
}
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法?
Array类有没有一种方法可以返回某种特定字段的引用?

arrays pointers scala reference scala-2.8

4
推荐指数
1
解决办法
4567
查看次数

在Scala中分配方法

执行此代码时:

var a = 24
var b = Array (1, 2, 3)
a = 42
b = Array (3, 4, 5)
b (1) = 42
Run Code Online (Sandbox Code Playgroud)

我在这里看到三个(五个?)作业.在这种情况下调用的方法调用的名称是什么?操作员是否超载?

更新:
我可以创建一个类和重载分配吗?(x = y不是x(1)= y)

scala operator-overloading variable-assignment scala-2.8

4
推荐指数
2
解决办法
3184
查看次数

奇怪的Scala错误

我试图创建基于抽象回合的游戏和抽象AI:

abstract class AGame {
  type Player
  type Move     // Player inside

  def actPlayer : Player
  def moves (player : Player) : Iterator[Move]
  def play (move : Move)
  def undo ()
  def isFinished : Boolean
  def result (player : Player) : Double
}

abstract class Ai[Game <: AGame] {
  def genMove (player : Game#Player) : Game#Move
}

class DummyGame extends AGame {
  type Player = Unit
  type Move = Unit

  def moves (player : Player) = new Iterator[Move] {
    def …
Run Code Online (Sandbox Code Playgroud)

types scala

4
推荐指数
1
解决办法
234
查看次数

Go的游戏算法?

Go游戏的算法技术水平是什么?
最好阅读哪些文章(描述算法)?

有一个专门用于Go 的StackExachge网站,但没有足够的人承诺在那里提出问题.

algorithm search artificial-intelligence baduk

4
推荐指数
1
解决办法
2223
查看次数

Scala解释器有哪些限制和解决方法?

什么样的构造需要'scalac'编译以及如何创建一个可以在解释器中工作的等价物?

编辑:我想使用scala而不是python作为脚本语言.(使用#!/ usr/bin/scala)

scala scala-2.8

4
推荐指数
1
解决办法
629
查看次数

如何为数组制作自定义toString?

我希望能够写:

val a = Array(1,2,3)
println(a.toString)
Run Code Online (Sandbox Code Playgroud)

并有一个有意义的打印输出.可能吗?

arrays scala scala-2.8

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

如何准确测量c ++函数使用的时钟周期?

我知道我必须使用:rdtsc.测量的函数是确定性的,但结果远非可重复(我从运行到运行得到5%的振荡).可能的原因是:

  • 上下文切换
  • 缓存未命中

你知道其他原因吗?如何消除它们?

performance benchmarking

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

64位移位问题

为什么这段代码不写0作为最后一个元素但是18446744073709551615?(用g ++编译)

#include <iostream>

using namespace std;
int main(){
    unsigned long long x = (unsigned long long) (-1);
    for(int i=0; i <= 64; i++)
        cout << i << " " << (x >> i) << endl;
    cout << (x >> 64) << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ 64-bit

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

是否可以重新编程键盘?

我的意思是真正的USB键盘,而不是软件键盘驱动程序.

我知道键盘有所不同,但总的来说它很容易/可以重新编程/重新连接吗?也许有些模型更容易做到这一点?

是的,我可以使用烙铁/硬件闪存重编程器.

hardware embedded

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