我对Common非常陌生,我正在努力学习如何使用网络套接字编程。在普通的lisp usocket中,它指定函数socket-send和socket-receive接受simple-array (unsigned-byte 8)缓冲区。
我对lisp太陌生了,无法理解如何在sbcl通用lisp中实现这一点。看来我可以使用函数vector和make-array,但不能使用simple-array,也不能使用如何将类型指定为unsigned-byte 8。
以下内容是否合理和类型正确?:
(let ((buffer (make-array (list-length input))) (input-length (list-length input)) )
(loop
for i upto input-length collect i do
(setf (nth i buffer) (parse-integer (nth i input))))
(usocket::socket-send socket buffer input-length)))如果不是,我如何完成我所需要的缓冲区的制作?
发布于 2017-08-05 21:04:37
CL-USER 25 > (make-array 10
:element-type '(unsigned-byte 8)
:initial-element 0)
#(0 0 0 0 0 0 0 0 0 0)
CL-USER 26 > (describe *)
#(0 0 0 0 0 0 0 0 0 0) is a (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (10))
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0映射:
CL-USER 32 > (map '(simple-array (unsigned-byte 8) (*)) #'char-code "foobarbaz")
#(102 111 111 98 97 114 98 97 122)或者更简单
CL-USER 33 > (map '(vector (unsigned-byte 8)) #'char-code "foobarbaz")
#(102 111 111 98 97 114 98 97 122)回:
CL-USER 34 > (map 'string #'code-char #(102 111 111 98 97 114 98 97 122))
"foobarbaz"https://stackoverflow.com/questions/45526302
复制相似问题