Is this a bug?

From: Andrew Dorrell <andrewd_at_ee.uts.edu.au>
Date: Sun, 25 Jun 95 15:17:10 EST

STkers,

I have been trying to write a class which inherits from the Canvas class for
doing some simple plotting. I need to initialise the canvas then make the
axis. Parameters for making the axis are defined within the new class:

(define-class <Plot> (<Canvas>)
  ((xaxis :accessor xaxis)
   (yaxis :accessor yaxis)
   (border :accessor border
                :initform 10
                :init-keyword :border)
  )
)

The problem is in intitialising:

(define-method initialize ((self <Plot>) initargs)
  (next-method)
  (let* ((xorigin (slot-ref self 'border))
         (yorigin (/ (slot-ref self 'height) 2))
         (xmin (slot-ref self 'border))
         (xmax (- (slot-ref self 'width) (slot-ref self 'border)))
         (ymax (- (slot-ref self 'height) (slot-ref self 'border)))
         (ymin (slot-ref 'self 'border)))
    (slot-set! self 'xaxis
        (make <Axis> :parent self
                        :coords (list xmin yorigin xmax yorigin)))
    (slot-set! self 'yaxis
        (make <Axis> :parent self
                        :coords (list xorigin ymin xorigin ymax)))
  )
)

With the above method, a call to make produces:
STk> (define p (make <Plot>))

*** Error:
slot-ref: bad instance: self

Looking at the stack suggests that the let clause is evaluated before the
call to (next-method). I can get rid of the problem by not using the (let
clause and recalculating the variables each time they are used as in:

(define-method initialize ((self <Plot>) initargs)
  (next-method)
  (slot-set! self 'xaxis
    (make <Axis> :parent self
                 :coords (list
                        (slot-ref self 'border)
                        (/ (slot-ref self 'height) 2)
                        (- (slot-ref self 'width) (slot-ref self 'border))
                        (/ (slot-ref self 'height) 2))))
  (slot-set! self 'yaxis
    (make <Axis> :parent self
                 :coords (list
                        (slot-ref self 'border)
                        (slot-ref self 'border)
                        (slot-ref self 'border)
                        (- (slot-ref self 'height) (slot-ref self 'border)))))
)

but this seems awkward.

Is this a bug? It seems that way to me. If not, could somebody please explain
to me what I have missed?

-- 
------------------------------------------------------------------------------
Mr Andrew Dorrell
School of Electrical Engineering                 *
University of Technology, Sydney                     *
PO Box 123                                     *
Broadway NSW 2007                                   .  
AUSTRALIA
                                                    *       /---\  Whoo?
Phone:   61 2 330 2395                                      (o o) /
Fax:     61 2 330 2435                                      ( : )  
email:   andrewd_at_ee.uts.edu.au                               ^ ^     
    OR   dorrell_at_ihf.uts.edu.au
------------------------------------------------------------------------------
Received on Sun Jun 25 1995 - 07:18:42 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST