我在一个命名空间中有以下内容shapes:
(derive ::rect ::shape)
(derive ::square ::rect)
Run Code Online (Sandbox Code Playgroud)
现在在shapes命名空间中执行以下命令:
(isa? ::square ::shape)
Run Code Online (Sandbox Code Playgroud)
回报true.但是当我在命名空间中执行以下操作时,我实际上为绘图实现了多个方法,
(isa? ::square ::shape)
Run Code Online (Sandbox Code Playgroud)
它返回false.因此,即使我有正确的多方法调度函数,我也会收到一条错误消息"未找到调度函数".
我错过了什么吗?在一个巨大的命名空间中实现所有类型的形状对我来说似乎毫无意义.
我无法理解这个错误.这个错误不在我正在调试的类中.(是吗?) 错误是:
c:\program files\microsoft visual studio 10.0\vc\include\fstream(890): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const std::basic_ifstream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
========== Build: 0 succeeded, 1 failed, 0 …Run Code Online (Sandbox Code Playgroud) 我需要知道对地图进行原位修改的最佳方法,而不需要修改值的本地副本,然后将其再次推送到原始地图中.
我已经详细介绍了下面解释问题的代码段:
#include <string>
#include <map>
struct EmployeeKey
{
std::string name;
int amount;
int age;
};
struct EmployeeDetail
{
std::string dept;
int section;
int salary;
};
bool compareByNameAge(const std::string& name,
const int& age,
const EmployeeKey& key )
{
return name > key.name && age > key.age;
}
typedef std::map<EmployeeKey, EmployeeDetail> EmployeeMap;
int main()
{
EmployeeMap eMap;
// insert entries to the map
int age = 10;
std::string name = "John";
EmployeeMap transformMap;
foreach( iter, eMap )
{
if ( compareByNameAge(name, …Run Code Online (Sandbox Code Playgroud) 我是Emacs和Clojure的初级用户,通过一些简单的文本处理来测试我的工作环境.我在获取Slime REPL以正确打印存储在向量中的UTF-8文本时遇到问题.
我首先将文件(Tocharian B的字典)的内容读入一个向量:
user> (def toch
(with-open [rdr (java.io.BufferedReader.
(java.io.FileReader. "/directory/toch.txt"))]
(vec (line-seq rdr))))
=> #'user/toch
Run Code Online (Sandbox Code Playgroud)
然后我尝试从向量中获取一行,然后我得到了垃圾:
user> (toch 44)
=> " Examples : /// kektse?±e akappi ste ‚Äòthe body is an impurity‚Äô (121b5), akappƒ´ = BHS a?õuci·?É (529a3). "
Run Code Online (Sandbox Code Playgroud)
我可以将字符串输入Slime REPL并将其恢复原样:
user> " Examples : /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akapp? = BHS a?uci? (529a3). "
=> " Examples : /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akapp? = BHS …Run Code Online (Sandbox Code Playgroud) 当我启动emacs GUI时,根据我的.zshrc不设置PATH.如何获取我的.zshrc来正确设置它?
编辑:我正在尝试使用swank-clojure但它找不到lein因为它不在PATH.
在使用Slime repl在Emacs中开发时,我无法重新加载多方法.
重新定义defmethod表单工作正常,但如果我更改调度功能,我似乎无法重新加载defmulti表单.我想我专门添加或删除了调度函数参数.
作为一种解决方法,我已经能够ns-unmap使用multimethod var,重新加载defmulti表单,然后重新加载所有defmethod表单.
据推测,这是Clojure实现多方法的一种"限制",即我们牺牲了一些执行速度的动力,但有没有任何成语或开发实践可以帮助解决这个问题?
当使用ClojureScript时,我尝试定义一个函数,它是对变量的闭包,如下所示:
(let [x 42]
(defn foo [n] (+ x n)))
Run Code Online (Sandbox Code Playgroud)
在Rhino REPL打印以下来源:
function foo(n){
return cljs.core._PLUS_.call(null,x__43,n);
}
Run Code Online (Sandbox Code Playgroud)
该函数按照我的预期工作,但是当试图获取名为的变量时,x__43我无法得到它.它去了哪里?
我想MAX_OPERATIONS从一个账户到另一个账户进行一定数量的资金转账.帐户作为refs存储在散列图调用程序中my-map(int account-id,double balance).
汇款需要从散列图"随机指数",并将它作为account-from对transfer.account-destination并且amount都应该修复.
不幸的是我不能让它发挥作用.
(defn transfer [from-account to-account amount]
(dosync
(if (> amount @from-account)
(throw (Exception. "Not enough money")))
(alter from-account - amount)
(alter to-account + amount)))
(defn transfer-all []
(dotimes [MAX_OPERATIONS]
(transfer (get mymap (rand-int[MAX_ACCOUNT]) :account-id) account-destination amount)))
Run Code Online (Sandbox Code Playgroud) Scheme(和CL)具有点对,其中单元的两个元素cons被明确地(例如(1 . 2))指定而不是隐式指定(例如(1 2),其被读取为(1 . (2 . nil))).
我遇到了这个难题,其中点对用于模式匹配,以捕获匹配对象中列表的尾部,例如:
(pmatch '(foo . (? pvar)) '(foo bar baz))
;; => ((pvar bar baz))
Run Code Online (Sandbox Code Playgroud)
这'(foo . (? pvar))是一个模式,'(foo bar baz)是与模式匹配的对象.foo在模式中是一个文字,而是(? pvar)一个模式变量,它匹配(bar baz)并将符号绑定pvar到该匹配.该pmatch函数返回模式变量和绑定匹配的关联列表.
如果模式已经存在'(foo (? pvar)),则匹配将失败,因为baz模式中的任何内容都不匹配.
我已经在Clojure中实现了这个难题,我将所有JRM的测试用例从虚线对中传递出来.我正在试图找出如何可能支持点对模式.
这是我目前的解决方案:
(defn pattern-variable? [pv]
(when (seq? pv)
(let [[qmark var] pv]
(and (= (count pv) 2)
(= qmark …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习Clojure并尝试定义这个简单的函数:
user=> (defn triple [arg] (* 3 arg))
#'user/triple
user=> (triple 1)
3
user=> (triple 1.01)
3.0300000000000002
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么在这里结果有2?
我有一个python脚本,它等待一些工作并在线程中执行它们(使用subprocess.Popenwith shell=True).当我在shell中运行脚本并尝试终止它时,Ctrl-C它会正常且干净地关闭.
问题是我想将此脚本作为守护程序运行,然后使用某种unix信号终止它.INT信号应该相同Ctrl-C但不能以相同的方式工作.它使子进程subproces.popen运行.
KeyboardInterupt当我收到信号时,我也试过在主线程中加注,但是也无法关闭脚本并杀死所有子进程.
任何建议如何模仿Ctrl-C?
致电subprocess.popen:
shell_cmd = "bwa aln -t 8 file1.fasta file1.fastq.gz > file1.sam.sai"
process = subprocess.Popen(shell_cmd,
shell=True,
stderr=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)