我对 clojure 还是很陌生,所以如果这有点微不足道,我深表歉意。基本上,问题出在 if 语句的“then”部分:(if(符号?(第一个 slist))。
;counts the number of occurences of
(defn count-occurrences [s slist]
(if (empty? slist)
0
(if (symbol? (first slist))
(if (= (first slist) s)
(+ 1 (count-occurrences s (rest slist)))
(+ 0 (count-occurrences s (rest slist))))
(count-occurrences s (first slist))))) ;Problem on this line
(println (count-occurrences 'x '((f x) y (((x z) x)))))
Run Code Online (Sandbox Code Playgroud) 我对Prolog有点陌生。我正在尝试编写一个函数子集(集合,子集),该函数确定子集是否是集合(duh)的子集。同样,如果第二个参数未实例化,则应输出每个可能的子集。现在,当实例化两个参数时它都可以工作,但是当我尝试输出所有子集时,它遇到了member / 2问题。例如:
?- subset([1,2,3], S).
S = [];
S = [1];
S = [1, 1];
S = [1, 1, 1];
...
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
% subset/2
% subset(Set, Subset) iff Subset is a subset of Set
subset(_, []).
subset(Set, [H|T]) :-
member(H, Set),
subset(Set, T).
Run Code Online (Sandbox Code Playgroud)
我如何做到这一点,以使成员不会继续选择Set中的第一个选项?
我有两个数据框,它们与一个非常长的用户ID相关,我想用更可读的东西替换这些值,比如一个简单的整数值.显然,我想在数据框架之间保持这些值一致,我想知道是否有一种简单的方法可以做到这一点.这是data.frames的样子:
ArtistData - 显示用户收听特定艺术家的次数:
UserID Artist Plays
00000c289a1829a808ac09c00daf10bc3c4e223b elvenking 706
00000c289a1829a808ac09c00daf10bc3c4e223b lunachicks 538
00001411dc427966b17297bf4d69e7e193135d89 stars 373
... ... ...
Run Code Online (Sandbox Code Playgroud)
UserData - 显示每个用户的信息:
UserID gender age country
00001411dc427966b17297bf4d69e7e193135d89 m 21 Germany
00004d2ac9316e22dc007ab2243d6fcb239e707d f 34 Mexico
000063d3fe1cf2ba248b9e3c3f0334845a27a6bf m 27 Poland
... ... ... ...
Run Code Online (Sandbox Code Playgroud)
所以基本上,我可以用每个数据帧之间一致的整数替换对我没有意义的长字符串吗?
我正在尝试创建一个简单的抽象类,以便多个子类可以实现一个方法.
我的抽象类:Component.h
#ifndef COMPONENT_H
#define COMPONENT_H
class Component {
public:
virtual void draw() = 0;
};
#endif
Run Code Online (Sandbox Code Playgroud)
实现的类:指令Memory.cpp
#include <Component.h>
#include <GL/gl.h>
using namespace std;
class InstructionMemory : public Component {
private:
float width = 145;
float height = 180;
public:
void Component::draw() {
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0, height);
glVertex2f(width, height);
glVertex2f(width, 0);
glEnd();
}
};
Run Code Online (Sandbox Code Playgroud)
现在,我收到一个错误:"无法在'InstructionMemory'中定义成员函数'Component :: draw'."
正如您所看到的,我正在尝试创建一个OpenGL项目,其中每个组件都可以绘制自己.
编辑:我想如果我包含抽象类,任何实现它的类都可以.我得到的是''InstructionMemory'未在此范围内声明." 我需要制作一个InstructionMemory.h吗?这是我的完整代码:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
#include <Math.h>
#include <my_headers/Component.h>
using namespace std;
const int WIDTH …Run Code Online (Sandbox Code Playgroud)