user1220978
user1220978

Reputation:

Using `satisfies` with `and` in Common Lisp

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?

Upvotes: 9

Views: 419

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139381

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.

Upvotes: 9

Related Questions