Guile 的 make-c-struct of (system foreign) 无法解释的行为
Unexplained behaviour of Guile's make-c-struct of (system foreign)
Guile 接受以下代码:
(use-modules (system foreign))
(define ptr (make-c-struct (list int int) '(300 43)))
然而,当第二行被替换为:
时它会抛出错误
(define ptr (make-c-struct '(int int) '(300 43)))
有人能推断出问题出在哪里吗?
$ guile --version
guile (GNU Guile) 2.0.13
$ uname -a
Linux <host> 4.8.0-1-amd64 #1 SMP Debian 4.8.5-1 (2016-10-28) x86_64 GNU/Linux
Backtrace:
In ice-9/boot-9.scm:
160: 8 [catch #t #<catch-closure 55b8628b8600> ...]
In unknown file:
?: 7 [apply-smob/1 #<catch-closure 55b8628b8600>]
In ice-9/boot-9.scm:
66: 6 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
432: 5 [eval # #]
In ice-9/boot-9.scm:
2404: 4 [save-module-excursion #<procedure 55b8628d89c0 at ice-9/boot-9.scm:4051:3 ()>]
4058: 3 [#<procedure 55b8628d89c0 at ice-9/boot-9.scm:4051:3 ()>]
In /home/<user>/path/tofile.scm:
7: 2 [#<procedure 55b862cf46c0 ()>]
In system/foreign.scm:
158: 1 [make-c-struct (int int) (300 43)]
In unknown file:
?: 0 [sizeof (int int)]
ERROR: In procedure sizeof:
ERROR: In procedure alignof: Wrong type argument in position 1: int
这个:
(list int int)
创建一个列表,其中包含先前定义的 int
值作为元素,而此:
'(int int)
创建一个包含两个 符号 作为元素的列表,它们不等价,请记住单引号是 shorthand 代表 (quote (int int))
,而不是(list int int)
.
Guile 接受以下代码:
(use-modules (system foreign))
(define ptr (make-c-struct (list int int) '(300 43)))
然而,当第二行被替换为:
时它会抛出错误(define ptr (make-c-struct '(int int) '(300 43)))
有人能推断出问题出在哪里吗?
$ guile --version
guile (GNU Guile) 2.0.13
$ uname -a
Linux <host> 4.8.0-1-amd64 #1 SMP Debian 4.8.5-1 (2016-10-28) x86_64 GNU/Linux
Backtrace:
In ice-9/boot-9.scm:
160: 8 [catch #t #<catch-closure 55b8628b8600> ...]
In unknown file:
?: 7 [apply-smob/1 #<catch-closure 55b8628b8600>]
In ice-9/boot-9.scm:
66: 6 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
432: 5 [eval # #]
In ice-9/boot-9.scm:
2404: 4 [save-module-excursion #<procedure 55b8628d89c0 at ice-9/boot-9.scm:4051:3 ()>]
4058: 3 [#<procedure 55b8628d89c0 at ice-9/boot-9.scm:4051:3 ()>]
In /home/<user>/path/tofile.scm:
7: 2 [#<procedure 55b862cf46c0 ()>]
In system/foreign.scm:
158: 1 [make-c-struct (int int) (300 43)]
In unknown file:
?: 0 [sizeof (int int)]
ERROR: In procedure sizeof:
ERROR: In procedure alignof: Wrong type argument in position 1: int
这个:
(list int int)
创建一个列表,其中包含先前定义的 int
值作为元素,而此:
'(int int)
创建一个包含两个 符号 作为元素的列表,它们不等价,请记住单引号是 shorthand 代表 (quote (int int))
,而不是(list int int)
.