【发布时间】:2016-05-22 12:35:23
【问题描述】:
我阅读了sbcl manual,并在 8.5 外部数据结构示例一章遇到了问题。
我使用以下示例来验证它是否可以正确运行。
_______________________________________________________________
或者考虑这个外部 C 变量和一些访问的例子:
struct c_struct {
short x, y;
char a, b;
int z;
c_struct *n;
};
extern struct c_struct *my_struct;
my_struct->x++;
my_struct->a = 5;
my_struct = my_struct->n;
在 Lisp 中可以这样操作:
(define-alien-type nil
(struct c-struct
(x short)
(y short)
(a char)
(b char)
(z int)
(n (* c-struct))))
(define-alien-variable "my_struct" (* c-struct))
(incf (slot my-struct 'x))
(setf (slot my-struct 'a) 5)
(setq my-struct (slot my-struct 'n))
________________________________________________________________
现在我在 slime 上运行上面的示例代码,它发出错误信号。
unknown alien type: C-STRUCT
[Condition of type SIMPLE-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [ABORT] Return to sldb level 7.
2: [RETRY] Retry SLIME REPL evaluation request.
3: [ABORT] Return to sldb level 6.
4: [RETRY] Retry SLIME REPL evaluation request.
5: [ABORT] Return to sldb level 5.***
我应该怎么做才能定义这样一个可以包含它的自身点的结构。
【问题讨论】:
标签: lisp common-lisp ffi sbcl