gpt4 book ai didi

lisp - 普通 lisp 中的强制函数——数组和列表

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:43 27 4
gpt4 key购买 nike

我在不同版本的 Common Lisp 之间看到了不同的强制行为 - 想知道哪个版本是“正确的”或者在这个看似简单的问题上标准是否含糊不清:

(coerce '(1 2 3) 'array) 

口齿不清?它在 Clozure Common Lisp 中运行良好,但在 sbcl 中运行不佳。

当它不起作用时,将列表强制转换为数组的最简单方法是什么?

谢谢

最佳答案

specification说:

If the result-type is a recognizable subtype of vector, and the object is a sequence, then the result is a vector that has the same elements as object.

array 不是 vector 的子类型——矢量是一维数组,但是 array 包括任意维数的数组。

你可以使用其中之一

(coerce '(1 2 3) 'vector)
(coerce '(1 2 3) '(array t (*)))

在第二个版本中,(*) 指定了未指定大小的单个维度。

您的用途未指定,因此实现可以随意实现。如果它返回一个值,该值必须是某种ARRAY

关于lisp - 普通 lisp 中的强制函数——数组和列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57468535/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com