在 Common Lisp 中使用 `satisfies` 和 `and`
Using `satisfies` with `and` in Common Lisp
我读到Google Common Lisp Style Guide (see the very last section) that there is a mistake in the Common Lisp standard regarding and
as a type specifier. Namely, that it does not "short circuit", or equivalently that order of evaluation is not guaranteed, contrary to what is assumed in the example:
(and integer (satisfies evenp))
但是,查看 CLtL2 的 section 4.4,它表示
When typep
processes an and
type specifier, it always tests each of the component types in order from left to right and stops processing as soon as one component of the intersection has been found to which the object in question does not belong.
而小节进一步说明,之所以如此,正是为了让satisfies
被其他类型过滤,避免出错。
我可以安全地假设这是 Google 风格指南中的一个错误,还是自 CLtL2 以来行为发生了变化?
几年前我遇到过同样的问题。
我在 ANSI CL 中找不到任何支持命令或过滤 的东西。但也没有 issue 讨论更改。您提到的示例采用 CLtL2 解释。
因此,假设编译器可能会重新排序类型并且这已从 CLtL2 更改。
我读到Google Common Lisp Style Guide (see the very last section) that there is a mistake in the Common Lisp standard regarding and
as a type specifier. Namely, that it does not "short circuit", or equivalently that order of evaluation is not guaranteed, contrary to what is assumed in the example:
(and integer (satisfies evenp))
但是,查看 CLtL2 的 section 4.4,它表示
When
typep
processes anand
type specifier, it always tests each of the component types in order from left to right and stops processing as soon as one component of the intersection has been found to which the object in question does not belong.
而小节进一步说明,之所以如此,正是为了让satisfies
被其他类型过滤,避免出错。
我可以安全地假设这是 Google 风格指南中的一个错误,还是自 CLtL2 以来行为发生了变化?
几年前我遇到过同样的问题。
我在 ANSI CL 中找不到任何支持命令或过滤 的东西。但也没有 issue 讨论更改。您提到的示例采用 CLtL2 解释。
因此,假设编译器可能会重新排序类型并且这已从 CLtL2 更改。