Using `satisfies` with `and` in Common Lisp
Asked Answered
A

1

9

I read in 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))

However, looking at section 4.4 of CLtL2, it's stated that

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.

And the section further explains that this is so, precisely to allow satisfies to be filtered by another type, to avoid errors.

Can I safely assume that this is a mistake in Google Style Guide, or has the behaviour changed since CLtL2?

Aliquant answered 21/4, 2015 at 10:0 Comment(0)
S
9

I've had the same problem a few years ago.

I found nothing in ANSI CL which would support an order or filtering. But there is also no issue which discusses a change. The example you mentioned assumes CLtL2 interpretation.

Thus it makes sense to assume that a compiler may reorder the types and that this has changed from CLtL2.

Sanalda answered 21/4, 2015 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.