
Implementing Baker’s SUBTYPEP decision procedure ELS’19, April 01–02 2019, Genova, Italy
10
1
10
2
10
3
10
−4
10
−3
10
−2
10
−1
10
0
Subtypes of NUMBER
10
1
10
2
10
−4
10
−3
10
−2
10
−1
10
0
MEMBER types
10
1
10
2
10
3
10
4
10
−4
10
−3
10
−2
10
−1
10
0
Subtypes of T
10
0
10
1
10
2
10
3
10
−4
10
−3
10
−2
10
−1
10
0
Subtypes of CONDITION
Algorithm 1 with cl:subtypep
Algorithm 1 with baker:subtypep
Algorithm 2 with cl:subtypep
Algorithm 2 with baker:subtypep
Figure 3: Comparative eciency measures of our subtypep
implementation
the result of the function
upgraded-array-element-type
returns giv-
ing that type. E.g, for
(make-array 2 :element-type ’list)
, the
implementation does not makes an array of
list
but rather an ar-
ray of
(upgraded-array-element-type ’list)
. For every value that
might return this function, Baker requires that we store a bit matrix
(instead of bit vectors) because of the complex bounds logic of the
type specier. As for the literal type procedure, it seems to be an
ecient type representation system—albeit more complex—which
nonetheless requires an extra registration step and a global state.
Baker does not mention the
cons
type specier family at all
in his article because it appeared after he released his article [
4
].
An accurate expert sub-procedure for this kingdom would have
an exponential complexity. More investigation is needed to assert
whether or not that exponential time is “acceptable” (as it is for
ranges) before rejecting it. The accuracy of existing
subtypep
pro-
cedures for the cons type specier also needs to be studied.
6 EARLY RESULTS
Our implementation of
subtypep
is still in active development and
very experimental. No serious optimization work has been made.
Nonetheless, Newton has compared in [
7
] the performances of
several
subtypep
highly dependent algorithms, both using the im-
plementation of Sbcl and ours.
These results, shown in Figure 3, are only presented here as
complementary information. On the horizontal axis is the size of
the type speciers and on the vertical axis is the measured exe-
cution time. Hence, the lower a curve is, the better. As expected,
our implementation is often slower, but not dramatically, which is
encouraging.
•
Our implementation is overall slower in the range type king-
dom.
•
Heavy users of
member
seems to experience a slower execu-
tion. Perhaps, as predicted by Baker, the reason is that the
systematic registration of the elements makes the size of
the bit-vectors grow quickly, thus making every subsequent
operation slower.
•
For the symbolic type speciers—primitive types, Clos
classes and conditions—our implementation already outper-
forms Sbcl’s.
7 CONCLUSION AND FUTURE WORK
Throughout this article we presented our implementation of Baker’s
decision procedure. In Section 2 we introduced the Common Lisp
type system, the notion of type specier and some vocabulary. In
Section 4 we explained how to pre-process the caller’s type speci-
ers to make the work of the expert sub-procedures presented in
Section 5 easier. We described our implementation for the symbolic,
member
, range and logical type speciers. We also gave some insights
about the implementation for the
array
and
cons
type speciers.
We nally presented some early eciency measures, which are
globally encouraging.
Our implementation is still a work in progress and highly exper-
imental. But with some cleaning and the implementation of both
array
and
cons
expert sub-procedures, it could be a viable alter-
native to existing
subtypep
implementations. We will have open
sourced its code by then. We still have to nd a solution for the
satisfies
type specier and the related uncertainty. Indeed, in some
situations,
subtypep
still can answer even though the type speci-
er is involved. For example, in
(subtypep ’string ’(and number
(satisfies evenp)))
, as the second operand is guaranteed to be
a subtype of
number
, the predicate can safely return false. Finally,
a lot of measures on accuracy and eciency are needed to assert
whether Baker’s intuition about his procedure was correct or not.
Even if, in the future, we are to conclude that our implementation
is less ecient than those which already exists, Baker’s algorithm
would still likely to improve the predicate’s accuracy. Lispers would
then have the ability to choose whichever
subtypep
implementation
ts their needs the best.
REFERENCES
[1]
Ansi. American National Standard: Programming Language – Common Lisp.
ANSI X3.226:1994 (R1999), 1994.
[2]
Ansi. American National Standard: Programming Language – Common Lisp –
Type Speciers (Section 4.2.3). ANSI X3.226:1994 (R1999), 1994. http://www.
lispworks.com/documentation/lw50/CLHS/Body/04_bc.htm.
[3]
Henry G. Baker. A Decision Procedure for Common Lisp’s
SUBTYPEP
Predicate.
Lisp and Symbolic Computation, 1992.
[4]
Paul F. Dietz. “subtypep tests” discussion on gcl-devel, 2005. https://lists.gnu.org/
archive/html/gcl-devel/2005-07/msg00038.html.
[5]
Graham Hutton. A tutorial on the universality and expressiveness of fold. Journal
of Functional Programming, 9(4):355–372, July 1999. URL http://dblp.uni-trier.de/
db/journals/jfp/jfp9.html#Hutton99.
[6]
Gregor J. Kiczales, Jim des Rivières, and Daniel G. Bobrow. The Art of the Metaobject
Protocol. MIT Press, Cambridge, MA, 1991.
[7]
Jim Newton. Representing and Computing with Types in Dynamically Typed Lan-
guages. PhD thesis, Sorbonne Université, Paris, France, November 2018.
[8]
Jim Newton and Didier Verna. Approaches in
typecase
optimization. In European
Lisp Symposium, Marbella, Spain, April 2018.
[9]
Peter Norvig. Paradigms of Articial Intelligence Programming: Case Studies in
Common Lisp. Morgan Kaufmann, 1992.