我想知道如何将一个lisp解释器嵌入到一个gui应用程序中,就像pyshell为Python做的那样.
我正在阅读"在lisp上",并遇到了这段代码(我简化了一下).
CL-USER> (defun foo ()
'(a b c))
FOO
CL-USER> (foo)
(A B C)
CL-USER> (nconc * '(D E))
(A B C D E)
CL-USER> (foo)
(A B C D E)
CL-USER> (defun foo ()
(list 'a 'b 'c))
STYLE-WARNING: redefining FOO in DEFUN
FOO
CL-USER> (foo)
(A B C)
CL-USER> (nconc * '(D E))
(A B C D E)
CL-USER> (foo)
(A B C)
Run Code Online (Sandbox Code Playgroud)
究竟是什么*意思?是以前的函数调用吗?它适合在现实世界的代码中使用吗?
为什么要(nconc * '(D E))改变第一个foo函数的返回值?
我一直以为(list 'a 'b …
我必须使用C++中的数组编写一个堆栈类模板.
这是我的代码:
#include <iostream>
template <typename Type>
class Stack {
private:
int top;
Type items[];
public:
Stack() { top = -1; };
~Stack() { delete[] items; };
void push(Type);
bool isEmpty() const;
Type pop();
Type peek() const;
};
int main (int argc, char *argv[]) {
Stack<double> st;
return 0;
}
template<typename Type>
void Stack<Type>::push(Type item) {
top++;
if(top == sizeof(items) / sizeof(Type)) {
Type buff[] = new Type[top];
std::copy(items,items+top,buff);
delete[] items;
items = new Type[2*top];
std::copy(buff,buff+top,items);
delete[] buff;
} …Run Code Online (Sandbox Code Playgroud) 我正在为我的任务实现一个avl树.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
struct TreeNode {
char *item;
struct TreeNode *left;
struct TreeNode *right;
signed char balance;
};
typedef struct TreeNode Node;
void _print_avl (Node *, int , const char *);
Node * get_new_node (char *);
int avl_insert(Node *, char *);
void print_avl (Node *);
void avl_swr(Node*);
int main (int argc, char *argv[])
{
Node *root = get_new_node("thura");
avl_insert(root, "thur2");
print_avl(root);
avl_insert(root, "thur1");
return 0;
}
int avl_insert(Node *root, char *item)
{
assert(root);
if( …Run Code Online (Sandbox Code Playgroud) 我有一个名为f1.txt的文件,其内容为75 15 85 35 60 50 45 70
这是我读取每个整数并打印它们的代码.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
fstream file("f1.txt", ios::in);
int i;
while(!file.eof()) {
file >> i;
cout << i << " ";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我编译并运行程序时,输出是75 15 85 35 60 50 45 70 70.为什么它读取最后一个整数两次?有线索吗?