From: Dennis Dunn
Subject: More fun with class slot initialization
Date: 
Message-ID: <jJki9.107606$AY5.41959901@e3500-atl1.usenetserver.com>
Hello.

First of all, thank you Gerd for the patch to CMUCL 18d to correct the
shared slot initialization bug.

My next problem also has to do with CMUCL, classes, and initialization of
slots.  For a class project, I am writing a neural network package.  In this
package, I have two classes representing neurons and the weights of the
connections between them.  A weight has a couple of slots that hold the
neurons at each end as well as the current value of the weight.

When I make an instance of a weight object, I pass the neuron objects via
initarg forms but then when I check the values of the various slots, I get
incorrect values.  In brief, the initarg for one slot seems to have been
applied to another slot.

For the following example, I used CMUCL 18d (the tarballs from
cmucl.cons.org) with a world that has Gerd's patch applied. I have included
a dribble log of the error as well as the two classes that I used in the
example.  Thank you very much for any comments you might have.

Dennis

;;;;
;;;; Log
;;;;
* (setf w (make-instance 'weight :input (make-instance 'neuron) :output
(make-instance 'neuron)))
Warning:  Declaring W special.
#<WEIGHT {48063245}>

* (weight-value w)

#<NEURON {48061AD5}>  ;;;;;;;;;;;; This is wrong.  The initform should set
this to a float.

* (weight-src w)

;;;;;;;;;;;; Whoa!  The source should be a neuron because of the initarg
form.  Even
;;;;;;;;;;;;  if the initarg wasn't applied, the initform should have been
and the
;;;;;;;;;;;; slot would have been bound to nil.

The slot SRC is unbound in the object #<WEIGHT {48063245}>

Restarts:
  0: [ABORT] Return to Top-Level.

Debug  (type H for help)

(PCL::|(FAST-METHOD SLOT-UNBOUND (T T T))| #<unused-arg>
                                           #<unused-arg>
                                           #<unused-arg>
                                           #<WEIGHT {48063245}>
                                           ...)
Source: Error finding source:
Error in function DEBUG::GET-FILE-TOP-LEVEL-FORM:  Source file no longer
exists:
  target:pcl/slots.lisp.
0]

;;;;
;;;; The classes used in the above example.
;;;;
(defclass weight ()
  ((src :documentation "The source neuron"
        :accessor weight-src
        :initform nil
        :initarg :input)
   (dst :documentation "The destination neuron"
        :accessor weight-dst
        :initform nil
        :initarg :output)
   (val :accessor weight-value
        :initform (1- (random 2.0)))
   (prev-delta :documentation "The value of the delta in the previous time
step."
               :accessor weight-prev-delta
               :initform 0.0)
   (alpha :documentation "The momentum constant for calculating
delta-weight."
          :allocation :class
          :accessor weight-alpha
          :initform 0.0)
   (learning-rate :documentation "Learning rate."
                  :allocation :class
                  :accessor weight-rate
                  :initform 1.0)))

(defclass neuron ()
  ((src-weights :documentation "The weights that feed into this neuron"
                :accessor neuron-src-weights
                :initform nil)
   (dst-weights :documentation "The weights getting input from this neuron"
                :accessor neuron-dst-weights
                :initform nil)
   (val :accessor neuron-value
        :initform 0.0
        :initarg :value)
   (eta :documentation "The error signal at this node"
        :accessor neuron-eta
        :initform 0.0)
   (threshhold :documentation "The threshhold added to the weighted sum."
               :allocation :class
               :accessor neuron-thresh
               :initform 0.0)
   (temperature :documentation "The temperature of the neuron for the
sigmoid."
                :allocation :class
                :accessor neuron-temp
                :initform 1.0)))