关于函数的说明 alexandria:length=

Clarification About the Function alexandria:length=

Alexandria Manual 包括一个用于测试序列长度的布尔函数:

Function: length= &rest sequences
Takes any number of sequences or integers in any order. Returns true iff the length of all the sequences and the integers are equal. Hint: there’s a compiler macro that expands into more efficient code if the first argument is a literal integer.

第一句讲的是“整数”(复数)。这是否只是为了测试几个计算的整数是否相同,同时测试序列长度?还是有更深层次的意义?

第三句提供了一个优化。这是否意味着当达到文字索引时,列表将停止计数,如果 lst 很长,它可能比 (= (length lst) 3) 更有效?

The first sentence talks about "integers" (plural). Is this simply for testing whether several computed integers are the same, at the same time as testing for sequence lengths? Or is there some deeper significance?

没有更深的意义。这可能只是为了对称。基本上,只有整数参数的 (length= ...) 只是一个较慢的 =。但是这个的主要用例是 (length= 3 (some-list)),即测试某个序列是否具有特定长度(“(some-list) 产生的序列值的长度是否为 3?”)。

The third sentence offers an optimization. Does this mean that counting over a list will stop when the literal index is reached, making it potentially more efficient than (= (length lst) 3) if lst is lengthy?

是的,确实是这样;编译器宏扩展为对 sequence-of-length-p 的调用,它(对于列表)执行类似于(通过 nthcdr)的操作。