我按照以下步骤操作:
http://localhost:8009/swank-js/test.html在Firefox中打开它.此时,我收到错误:
ReferenceError: document is not defined
at repl:1:1
at DefaultRemote.evaluate (/usr/lib/nodejs/swank-js/swank-handler.js:314:9)
at Executive.listenerEval (/usr/lib/nodejs/swank-js/swank-handler.js:414:21)
at Handler.receive (/usr/lib/nodejs/swank-js/swank-handler.js:169:20)
at SwankParser.onMessage (/usr/lib/nodejs/swank-js/swank.js:50:17)
at SwankParser.handleMessage (/usr/lib/nodejs/swank-js/swank-protocol.js:75:8)
at SwankParser.handleContent (/usr/lib/nodejs/swank-js/swank-protocol.js:62:10)
at SwankParser.execute (/usr/lib/nodejs/swank-js/swank-protocol.js:53:20)
at Socket.<anonymous> (/usr/lib/nodejs/swank-js/swank.js:60:16)
at Socket.emit (events.js:67:17)
Run Code Online (Sandbox Code Playgroud)
我应该使用require()还是什么?我仍然有点朦胧swank/slime/node正在沟通,所以请原谅这个问题的黑盒子性质.:d
我正在处理一个对象,特别是它的一个函数,它看起来像这样:
public class Dog {
private ArrayList<Paw> paws;
private double age;
private Tongue tongue;
public Dog(ArrayList<Paw> paws, double age, Tongue tongue) {
this.paws = paws;
this.age = age;
this.tongue = tongue;
}
public void bark() {
// ... about 100 lines of side effects operating
// on the object's global members ...
}
}
Run Code Online (Sandbox Code Playgroud)
我真的想要修复这些副作用并将对象重构为只做一件事的函数.
Eclipse中是否有自动化过程来标记可能的副作用?
如果没有,是否有我可以遵循的手动算法,所以我不会迷失在兔子洞里?
我的问题是为什么人们创建目录结构至少有一个名为edu的文件夹,然后是另一个名为mit的文件夹(例如),然后是子文件夹中的所有代码?
这是某种标识符吗?
计算机实际上是出于任何原因使用该结构 - 还是仅用于帮助读者?
如果是这样,它对读者有何帮助?
下图是否表明我正在使用内存并且它没有被垃圾回收?

一旦我开始使用较少的堆,我预计橙色图(分配的堆)会下降.
我正在编写一个程序来使用Haskell解析.TGA文件 - 但是,性能绝对可怕.2048 x 2048像素图像需要几秒钟才能解析.
我运行了我的代码+RTS -p -RTS并收到了报告中的以下有趣内容:
total time = 1.08 secs
total alloc = 3,037,568,120 bytes
COST CENTRE MODULE %time %alloc
readPixelMap Main 33.0 11.0
readPixelMap.getByte Main 32.7 75.1
readPixelMap.getColor Main 27.0 13.3
Run Code Online (Sandbox Code Playgroud)
看来我的程序在函数中分配了大量的内存readPixelMap.该函数如下所示:
readPixelMap width height = do
pixels <- replicateM height (replicateM width getColor)
return $ PixMap pixels
where getByte = liftM toInteger getWord8
getColor = do (red:green:blue:alpha:xs) <- replicateM 4 getByte
return (red, green, blue, alpha)
Run Code Online (Sandbox Code Playgroud)
和a PixMap定义为 …
我正在使用Haskell和Parsec来解析文件格式.我的解析函数类似于:
parseInput :: String -> Model
parseInput input = ...
data Model = Model { mNumV :: Int, mNumF :: Int, ... }
Run Code Online (Sandbox Code Playgroud)
为了测试这个,我使用的是QuickCheck.我已经定义了一个Arbitrary生成String表示格式化文件内容的实例:
instance Arbitrary File where
arbitrary = ...
data File = File { fContents :: String, fNumV :: Int, fNumF :: Int, ... }
Run Code Online (Sandbox Code Playgroud)
我的一个属性可能会检查以确定mNumV == fNumV在解析任意后是否String.这很有效 - 当它工作时.
但如果出现问题,Parsec会抛出类似于的错误:
*** Failed (after 1 test):
Exception:
(line 302, column 3):
unexpected "\n"
expecting space
Run Code Online (Sandbox Code Playgroud)
这很有用 - 但是,在测试失败后,任意文件的内容都会消失.我不能进去参考302行.
我能看到的唯一选择是fContents …
我正在实施Gilbert-Johnson-Keerthi算法,该算法计算两个物体是否相交(即碰撞).
我的代码的入口点是hasCollided函数,它接受两个点列表并True在它们相交时返回.我相信我已经正确地实现了论文 - 但是,我仍然需要实现这个contains功能.
该contains函数应确定单纯形是否包含原点.我不确定如何实现这一点.
如何有效地确定单形(点集合)是否包含原点?
以下是我的实施:
type Simplex = Set (Vector Double)
hasCollided :: [Vector Double] -> [Vector Double] -> Bool
hasCollided points1 points2 = gjk points1 points2 simplex (scale (-1) direction) p
where simplex = insert p empty
p = support points1 points2 direction
direction = fromList [1, 0, 0]
gjk :: [Vector Double] -> [Vector Double] -> Simplex -> Vector Double -> Vector Double -> Bool
gjk …Run Code Online (Sandbox Code Playgroud) 为什么当我围绕此代码包装SwingWorker时,它不再报告抛出异常?
import java.security.InvalidParameterException;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
public class Test {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
IntegerString s = new IntegerString("EIGHT");
return null;
}
}.execute();
}
});
}
}
class IntegerString {
public IntegerString(String s) {
if (!isInteger(s)) {
System.out.println("...throwing exception.");
throw new InvalidParameterException("Thrown.");
}
// ...
}
static boolean isInteger(String str) {
if (str == null) {
return false; …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种算法来查找二进制图像中的所有连接组件.
如果我们将图像看作矩阵,它看起来像:
[ 0 0 0 0 ...
0 0 0 0 ...
0 1 1 1 ...
0 1 0 1 ...
0 1 0 0 ...
...
]
Run Code Online (Sandbox Code Playgroud)
我想找到所有触摸的对角线(对角线).在此示例中,只有一个组件 - 但图像中可能有数百个独特组件.
Image => ALGORITHM => [ [(x,y)], ... ]
# list of lists of coordinates (each shape is a list)
Run Code Online (Sandbox Code Playgroud)
我已经看过维基百科上的两个通过标记算法,但我不相信它会给我带来实际的组件 - 它只是标记了不同的组件.(或者这个和那个一样吗?)
如果可能,这应该能够针对视频流实时运行.
language-agnostic algorithm image-recognition computer-vision
我正在编写Vector和Matrix依赖类型的数据类型.
data Vector n e where
EmptyVector :: Vector Zero e
(:>) :: e -> Vector n e -> Vector (Succ n) e
deriving instance Eq e => Eq (Vector n e)
infixr :>
data Matrix r c e where
EmptyMatrix :: Matrix Zero c e
(:/) :: Vector c e -> Matrix r c e -> Matrix (Succ r) c e
deriving instance Eq e => Eq (Matrix r c e)
infixr :/
Run Code Online (Sandbox Code Playgroud)
它们取决于自然数,也取决于类型.
data …Run Code Online (Sandbox Code Playgroud)