[Openmcl-devel] Type-of and positive/negative integers

Tim Bradshaw tfb at tfeb.org
Thu Oct 24 07:46:53 PDT 2019

On 24 Oct 2019, at 14:06, Steven Nunez <steve_nunez at yahoo.com> wrote:
> (deftype simple-double-float-vector (&optional (length '*))
>   "Simple vector of double-float elements."
>   `(simple-array double-float (,length)))

One trick you could do to make claims about types which should be checked fairly fast (but, don't do this in an inner loop), if you have a list of things all of which you want to be of some good type, is

(coerce list-of-things '(vector good-type))

And then write inner loops which assume suitable vectors of good-type objects.

This has one nice property and one nasty one.  The nice property is that (coerce (coerce something a-type) a-type) only conses one instance of a-type, so you can write functions which take either lists of elements or things you've already turned into vectors.

The nasty property is that you have to be aware of upgraded-array-element-type and in particular it does not have to be the case that (coerce '(1 2 3) '(vector fixnum)) returns a vector of fixnums: it could easily return a vector of machine integers, which will be bigger than fixnums.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20191024/5a85a8d8/attachment.htm>

More information about the Openmcl-devel mailing list