On 22 Sep 2013, at 16:56, Scott McKay <swmckay@gmail.com> wrote:

On Sun, Sep 22, 2013 at 9:53 AM, Pascal Costanza <pc@p-cos.net> wrote:
Hi,

It seems to me that ASSERT and CHECK-TYPE are not as convenient as they could be. In particular, ISLISP seems to have a better alternative in ASSURE.

ASSURE is easy to define:

(defmacro assure (type form)
  (let ((object (copy-symbol 'object)))
    `(let ((,object ,form))
       (check-type ,object ,type)
       ,object)))


Yeah, this is really useful. One question -- is it also worth putting
in (declare (type ,object ,type)) after the let-binding? Or does every
competent compiler do the right thing once it's seen 'check-type'?

The type is only guaranteed after the check-type, so I don't think it's valid to put such a type declaration immediately after the let binding. After the check-type, it does not make much sense anymore, because immediately afterwards, the object is just returned.


Pascal


--
Pascal Costanza
The views expressed in this email are my own, and not those of my employer.