[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defclass problem?



 >Date: Thu, 27 Jan 1994 18:10:38 -0600
 >To: info-mcl@cambridge.apple.com
 >From: osiris@cs.utexas.edu (Rob Browning)
 >Subject: defclass problem?
 >
 >Why do I get this complaint?  It is apparently a conflict between the line
 >slot of this class and the quickdraw line method.  However, I was under the
 >impression that methods did not incurr this kind of name clash.
 >
 >? (defclass ccc () ((line :accessor line :initarg :line)))
 >> Error: Incompatible lambda list in #<STANDARD-READER-METHOD LINE (CCC)> for
 >>#<STANDARD-GENERIC-FUNCTION LINE #xD8CAC6>
 >> While executing: CCL::CHECK-DEFMETHOD-CONGRUENCY
 >> Type Command-/ to continue, Command-. to abort.
 >
 >--Thanks.
 >
 >P.S. Thanks for all of your help with my earlier questions.
 >

You're right, it is a conflict between 
 1) a method called LINE, which you specified as the slot accessor, and 
 2) the method called LINE, the quickdraw command to draw a line.

There's nothing about methods which guarantee avoiding name clashes
like these (as a matter of fact, it's sometimes desirable).

You have a couple of options:

 a) You can change the package in which you write your software.
    Use something like (defpackage my-package (:use common-lisp))
    when you load your code, and at the top of your file, use 
    (in-package my-package) to switch your file to the right package.

    Then, in your code, LINE refers to the slot, and CCL::LINE refers
    to the quickdraw line function.

    This is probably the cleanest and best way to enforce name modularity -
    unlike C++, lisp uses names, not objects, to avoid name clashes.
    Using packages properly takes some study, however. MCL tells you
    a window's current package by showing it in the lower left corner.

 b) You can change the :accessor of your slot to CCC-LINE:

     (defclass ccc () ((line :accessor ccc-line :initarg :line)))
 
   This will rename the methods for reading and writing the slot.