In [8] Hosoya et al. introduce a semantic type approach to
describe a system which enables their compiler to guarantee
that an XML document conform to the intended type. The
paper deals heavily with assuring that the regular expression
types are well defined when defined recursively, and that
decisions about subtype relationships can be calculated and
exploited.
A notable distinction of the rte implementation as op-
posed to the XDuce language is that our proposal illustrates
adding such type checking ability to an existing type system
and suggests that such extensions might be feasible in other
existing dynamic or reflective languages.
The concept of regular trees, is more general that what rte
supports, posing interesting questions regarding apparent
shortcomings of our approach. The semantic typing concept
described in [8] indeed seems to have many parallels with
the Common Lisp type system in that types are defined by
a set of objects, and sub-types correspond to subsets thereof.
These parallels would suggest further research opportunities
related to rte and Common Lisp. However, the limitation
that rte cannot be used to express trees of arbitrary depth
as discussed in Section 4.1 seems to be a significant limita-
tion of the Common Lisp type system. Furthermore, the use
of satisfies in the rte type definition, seriously limits the
subtypep function’s ability to reason about the type. Con-
sequently, programs cannot always use subtypep to decide
whether two rte types are disjoint or equivalent, or even if
a particular rte type is empty. Neither can the compiler
dependably use subtypep to make similar decisions to avoid
redundant assertions in function declarations.
It is not clear whether Common Lisp could provide a way
for a type definition in an application program to extend
the behavior of subtypep. Having such a capability would
allow such an extension for rte. Rational language the-
ory does provide a well defined algorithm for deciding such
questions given the relevant rational expressions [9, Sections
4.1.1, 4.2.1]. It seems from the specification that a Com-
mon Lisp implementation is forbidden from allowing self-
referential types, even in cases where it would be possible to
do so.
6. CONCLUSIONS
In this paper we presented a Common Lisp type definition,
rte, which implements a declarative pattern based approach
for declaring types of heterogeneous sequences illustrating it
with several motivating examples. We further discussed the
implementation of this type definition and its inspiration
based in rational language theory. While the total compu-
tation needed for such type checking may be large, our ap-
proach allows most of the computation to be done at compile
time, leaving only an O(n) complexity calculation remaining
for run-time computation.
Our contributions are
1. recognizing the possibility to use principles from ratio-
nal theory to address the problem dynamic type check-
ing of sequences in Common Lisp,
2. adapting the Brzozowski derivative algorithm to se-
quences of lisp types by providing an algorithm to sym-
bolically decompose a set of lisp types into an equiva-
lent set of disjoint types,
3. implementing an efficient O(n) algorithm to pattern
match an arbitrary lisp sequence, and
4. implementing concrete rte based algorithms for recog-
nizing certain commonly occurring sequence patterns.
For future extensions to this research we would like to ex-
periment with extending the subtypep implementation to al-
low application level extensions, and therewith examine run-
time performance when using rte based declarations within
function definitions.
Another topic we would like to research is whether the
core of this algorithm can be implemented in other dynamic
languages, and to understand more precisely which features
such a language would need to have to support such imple-
mentation.
7. REFERENCES
[1] Declaring the elements of a list, discussion on
comp.lang.lisp, 2015.
[2] H. G. Baker. A decision procedure for Common Lisp’s
SUBTYPEP predicate. Lisp and Symbolic
Computation, 5(3):157–190, 1992.
[3] J. A. Brzozowski. Derivatives of regular expressions. J.
ACM, 11(4):481–494, 1964.
[4] R. D. Cameron. Perl style regular expressions in
Prolog, CMPT 384 lecture notes, 1999.
[5] J. Chroboczek. CL-Yacc, a LALR(1) parser generator
for Common Lisp, 2009.
[6] P. Domain. Alexandria implementation of
destructuring-case.
[7] N. Funato. Public domain implementation of
destructuring-bind, 2013.
[8] H. Hosoya, J. Vouillon, and B. C. Pierce. Regular
expression types for XML. ACM Trans. Program.
Lang. Syst., 27(1):46–90, Jan. 2005.
[9] J. D. U. Johh E. Hopcroft, Rajeev Motwani.
Introduction to Automata Theory, Languages, and
Computation. Addison Wesley, 2001.
[10] W. H. Newman. Steel Bank Common Lisp user
manual, 2015.
[11] J. Newton. Report: Efficient dynamic type checking of
heterogeneous sequences. Technical report,
EPITA/LRDE, 2016.
[12] S. Owens, J. Reppy, and A. Turon. Regular-expression
derivatives re-examined. J. Funct. Program.,
19(2):173–190, Mar. 2009.
[13] C. Rhodes. User-extensible sequences in Common
Lisp. In Proceedings of the 2007 International Lisp
Conference, ILC ’07, pages 13:1–13:14, New York, NY,
USA, 2009. ACM.
[14] A. Shinn, J. Cowan, and A. A. Gleckler. Revised 7
report on the algorithmic language scheme. Technical
report, 2013.
[15] Ansi. American National Standard: Programming
Language – Common Lisp. ANSI X3.226:1994
(R1999), 1994.
[16] E. Weitz. Common Lisp Recipes: A Problem-solution
Approach. Apress, 2015.
[17] G. Xing. Minimized Thompson NFA. Int. J. Comput.
Math., 81(9):1097–1106, 2004.
[18] F. Yvon and A. Demaille. Th´eorie des Langages
Rationnels. 2014.