License: Public Domain , Load it with Quicklisp: (ql:quickload "enhanced-typep")
Library type: Convenience function , Project complexity: Trivial

enhanced-typep obsoletes all typep thin wrappers.


25 standard Common Lisp symbols are entirely dedicated to naming pure trivial typep thin wrappers. These functions, while arguably convenient, are almost pure overhead, and they represent 2.6% of standard Common Lisp symbols. Compare:

(stringp object)
(typep object 'string)

While the latter is slightly longer, think about all the overhead that goes into implementing, defining, documenting, learning and otherwise managing all pure trivial typep wrappers, including the standard and user-defined ones.

We can use a more orthogonal approach, just by always using typep directly. However, some code would become very annoying to write:

(remove-if #'stringp '("string" symbol "other string"))
(remove-if (lambda (o) (typep o 'string)) '("string" symbol "other string"))

This is clearly unacceptable. We could make up some trivial function that takes a type and returns a closure that calls typep on its argument and the type, but what to call it? This library simply provides an enhanced version of typep that is exactly like the original, except it can also accept a single type argument, in which case it returns the appropriate closure:

(remove-if #'stringp '("string" symbol "other string"))
(remove-if (typep 'string) '("string" symbol "other string"))


Dictionary » enhanced-typep

Package enhanced-typep


Simply (:shadowing-import-from #:enhanced-typep #:typep) from your defpackage. Don't (:use)!

Dictionary » typep

Function typep

object type &optional environment => generalized-boolean


type => function

Arguments and Values


The semantics are exactly the same as for cl:typep, except that if only one argument is supplied, then that argument is treated as a type and we return a function of one argument object that, when called, returns the result of calling cl:typep on the object and type. (No provision is made for passing an environment parameter in that case, but this is virtually never needed anyway.)

To help ensure proper optimization, this function is declaimed inline, its ftype is declared, and an appropriate compiler macro is defined so that we expand directly to a cl:typep with the same arguments if at least 2 arguments were passed, else we expand directly to an optimized lambda.