// File (or directory) to be moved
File file = new File("filename");
// Destination directory
File dir = new File("directoryname");
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) {
// File was not successfully moved
//can it be because file with file name already exists in destination?
}
Run Code Online (Sandbox Code Playgroud)
如果目标中已存在名称为"filename"的文件,则会将其替换为新文件吗?
有没有办法 在Lua中进行逻辑编程(想想Prolog)?
特别是:有没有用于逻辑编程的Lua模块(miniKanren实现将是最好的,但并不是严格要求的)?因为我找不到任何[1].如果没有,是否有任何已知的(最好尝试过)如何在Lua中进行逻辑编程?
另外:有没有人试图在Lua中做类似逻辑编程的事情?
[1]到目前为止,我发现只有博客文章提到在Metalua中写一个的可能性,但我宁愿看到一个兼容标准的Lua.
我一直在尝试在我的计算机上安装Clojure来学习和使用.我正在运行Ubuntu 10.04,并已从Synaptic安装了最新的Sun Java SDK和环境.
通过Google搜索,我找到了多个指南,为如何安装所有依赖项和有用的工具以及如SLIME的ant,maven,leiningen和emacs等构建器提供了非常明确的指南.
有些指南有点陈旧,特别是考虑到Clojure开发的速度有多快,所以我搜索了最新的指南.我从2010年12月开始关注这个指南,它和大多数其他人非常相似.
我遇到的一个大问题是我必须启动REPL的步骤
java -cp clojure.jar clojure.main
Run Code Online (Sandbox Code Playgroud)
我在clojure源代码中看到了我从github.com/clojure/clojure.git和github.com/clojure/clojure-contrib.git得到的,它实际上没有一个clojure.jar来指向JVM ......
我想也许有些事情我做错了,因为在谷歌搜索之前没有人遇到过这个问题.我通过浏览器仔细检查了Github上的repos,并且那里也没有.jar文件.
那么......我在哪里可以获得这个.jar文件,还是有其他方式我应该去做这件事?
我想构建一个函数,给定一个2D矩阵和该矩阵中的一些元素,它将返回元素位置的索引:
(get-indices [[1 2 3] [4 5 6] [7 8 9]] 6)
;=> [1 2]
Run Code Online (Sandbox Code Playgroud)
返回到get-in,将返回元素本身:
(get-in [[1 2 3] [4 5 6] [7 8 9]] [1 2])
;=> 6
Run Code Online (Sandbox Code Playgroud)
我希望函数(get-indices)快,所以我在考虑做一个宏,它会扩展到类似于(cond ...)这个函数的部分(但对于每个大小为NxN的2D矩阵都是通用的):
(defn get-indices
[matrix el]
(let [[[a b c] [d e f] [g h i]] matrix]
(cond
(= a el) [0 0]
(= b el) [0 1]
(= c el) [0 2]
(= d el) [1 0]
(= e el) [1 1]
(= f el) [1 2] …Run Code Online (Sandbox Code Playgroud)