Subject: Re: Lisp vs Java
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 16 Oct 2008 04:53:12 -0500
Newsgroups: comp.lang.lisp
Message-ID: <qKWdnSrCV_OVkmrVnZ2dnUVZ_h6dnZ2d@speakeasy.net>
Christian Lynbech  <christian@defun.dk> wrote:
+---------------
| The condition system was mentioned; without having looked very carefully
| it does not seem obvious that SBCL implements conditions as CLOS
| objects, so indeed I think that one could carve out CLOS if one wanted
| to relatively easy (depending on the specific implementation).
+---------------

I can't speak to SBCL, but CMUCL implements conditions as a variant
of structure [which, however, is not actually of type STRUCTURE]:

    cmu> (make-condition 'error)

    #<ERROR {4898CC95}>
    cmu> (describe *)

    #<ERROR {4898CC95}> is a structure of type ERROR.
    FUNCTION-NAME: NIL.
    ACTUAL-INITARGS: NIL.
    ASSIGNED-SLOTS: NIL.
    cmu> (type-of **)

    ERROR
    cmu> (subtypep * 'condition)

    T
    T
    cmu> (subtypep ** 'structure)

    NIL
    T
    cmu> 

But then there are special type hacks layered on top that make such
objects *appear* to be CLOS types, even though they aren't, really.  ;-}

    cmu> (find-class 'error)

    #<CONDITION-CLASS ERROR {290C9EFD}>
    cmu> (type-of *)

    PCL::CONDITION-CLASS
    cmu> 

But as the CLHS says, you can't use MAKE-INSTANCE to make a CONDITION,
you have to use MAKE-CONDITION[1].


-Rob

[1] Or ERROR, CERROR, etc., which call MAKE-CONDITION internally:

    cmu> (describe
	  (second
	   (multiple-value-list
	    (ignore-errors
	     (error "Wrong value: ~s" 5)))))

    #<SIMPLE-ERROR {489DA80D}> is a structure of type SIMPLE-ERROR.
    FUNCTION-NAME: "Top-Level Form".
    ACTUAL-INITARGS: (:FORMAT-CONTROL "Wrong value: ~s" :FORMAT-ARGUMENTS (5)).
    ASSIGNED-SLOTS: NIL.
    cmu> 

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607