From: ········@ptcstudios.com
Subject: CLOS slot :type property
Date: 
Message-ID: <uh1vOaJk9aMDtapmLkx9SsZmv1ln@4ax.com>
Hi-

When defining CLOS slots, there is a slot property called :type.  The
docuementation that I have read indicates that this slot is to be the
'type' of the value stored in the slot.  However, no type checking
appears to be done.  Example.

(defclass foo () ((data :initform 7 :initarg :data :accessor foo-data
:type integer)))

(setf new-foo (make-instance 'foo))

Then calling: (setf (foo-data new-foo) "anything")

should cause an error, but it doesn't.  The value is happily set and
calling:
(foo-data new-foo) 
returns "anything".


Can some explain if the :type property is just for documentation and
type-checking must be done by the implementation, or if I am missing
something?

Thanks so much,
········@ptcstudios.com

From: Barry Margolin
Subject: Re: CLOS slot :type property
Date: 
Message-ID: <0wGb5.81$BL6.1824@burlma1-snr2>
In article <····························@4ax.com>,
 <········@ptcstudios.com> wrote:
>Hi-
>
>When defining CLOS slots, there is a slot property called :type.  The
>docuementation that I have read indicates that this slot is to be the
>'type' of the value stored in the slot.  However, no type checking
>appears to be done.  Example.

It's not for type checking, it's for type declaration, like (DECLARE (TYPE
...)) in a function.  It allows for potential optimization; for instance,
if a slot is declared :TYPE FIXNUM, it could be implemented as an immediate
value rather than as a boxed object.  And when the accessor is called, the
compiler may be able to know that it always returns a particular type, so
type dispatching can be avoided.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Roger Corman
Subject: Re: CLOS slot :type property
Date: 
Message-ID: <396f42f3.147271184@news>
On Fri, 14 Jul 2000 15:40:44 GMT, Barry Margolin <······@genuity.net>
wrote:

>In article <····························@4ax.com>,
> <········@ptcstudios.com> wrote:
>>Hi-
>>
>>When defining CLOS slots, there is a slot property called :type.  The
>>docuementation that I have read indicates that this slot is to be the
>>'type' of the value stored in the slot.  However, no type checking
>>appears to be done.  Example.
>
>It's not for type checking, it's for type declaration, like (DECLARE (TYPE
>...)) in a function.  It allows for potential optimization; for instance,

But with the compiler's safety setting up high, it is reasonable to
expect that some type checking might occurs as a result of
declarations.


·····@corman.net
From: Barry Margolin
Subject: Re: CLOS slot :type property
Date: 
Message-ID: <G0Mb5.108$BL6.2417@burlma1-snr2>
In article <··················@news>, Roger Corman <·····@corman.net> wrote:
>On Fri, 14 Jul 2000 15:40:44 GMT, Barry Margolin <······@genuity.net>
>wrote:
>
>>In article <····························@4ax.com>,
>> <········@ptcstudios.com> wrote:
>>>Hi-
>>>
>>>When defining CLOS slots, there is a slot property called :type.  The
>>>docuementation that I have read indicates that this slot is to be the
>>>'type' of the value stored in the slot.  However, no type checking
>>>appears to be done.  Example.
>>
>>It's not for type checking, it's for type declaration, like (DECLARE (TYPE
>>...)) in a function.  It allows for potential optimization; for instance,
>
>But with the compiler's safety setting up high, it is reasonable to
>expect that some type checking might occurs as a result of
>declarations.

I think one Lisp implementation does that, but most don't.  I'm not sure
which implementation it is, though.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Kenneth P. Turvey
Subject: Re: CLOS slot :type property
Date: 
Message-ID: <slrn8mupqt.8g4.kt-alt@pug1.sprocketshop.com>
On Fri, 14 Jul 2000 14:01:24 GMT, ········@ptcstudios.com <········@ptcstudios.com> wrote:
>Hi-
>
>When defining CLOS slots, there is a slot property called :type.  The
>docuementation that I have read indicates that this slot is to be the
>'type' of the value stored in the slot.  However, no type checking
>appears to be done.  Example.
[Example elided]

In Lisp, unlike many other languages, type declaration is for
optimization only.  Declarations are promises the programmer makes to
the compiler.  The compiler may check the types, but doesn't have to.
The compiler may rely on the values actually having the types you have
declared, or not.  The compiler may completely ignore the declaration.  

-- 
Kenneth P. Turvey <······@SprocketShop.com> 
  http://www.tranquility.net/~kturvey/resume/resume.html
--------------------------------------------------------
  As we enjoy great advantages from the inventions of others, we should
  be glad of an opportunity to serve others by any invention of ours.
        -- Benjamin Franklin