[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Type Specifier: (OR (FUNCTION ...) ...)
Question: What is the 'most informative' type specifier for
the CL function COPY-SEQ?
How 'bout?
(function (sequence) sequence)
Unfortunately, this does not tell the reader nor the compiler that if
the argument is a list, then the result is also a list, and vice
versa. So how about this:
(or (function (list) list)
(function (vector) vector))
This is syntactically valid CL, and the definition of the OR and
FUNCTION type specifiers makes it meaningful. Unfortunately, it is
not clear from pg. 158 whether or not the following is legal:
(proclaim '(ftype (or (function (list) list)
(function (vector) vector))
copy-seq))
It is not legal in VaxLisp, and my guess is that there aren't any
implementations that would do the right thing with it. So I would like
to propose that such a use of OR/FUNCTION be considered legal CL.
Without such a declaration, one is forced to either wrap
(the <result-type> ...) around all calls to such functions or to
DECLARE a restricted version of FUNCTION in the appropriate places,
e.g.,
(defun foo (alist avector)
(declare (list alist)
(vector avector)
(function copy-seq (list) list))
(zap (copy-seq alist)
(let ()
(declare (function copy-seq (vector) vector))
(zoop (copy-seq avector))))
Either method is a real pain.
This use of OR would give CL something akin to Ada overloading. It
allows the overloading of multiple 'function type signatures' on a
single function name. Such overloading is already implicit throughout
CL (esp. the seq. functions). My proposal would merely allow a way of
describing it.
-- Nick