Re: initialization of slots

From: Erick Gallesio <eg_at_unice.fr>
Date: Thu, 11 Mar 1999 19:43:39 +0100 (CET)

Brian Denheyer writes:
>
> I am wondering if there is a way to initialize a slot through the
> execution of a procedure. For example,
>
> (define-class <foo> ()
> ((slot :accessor slot
> :init-keyword :slot)))
>
> Let's say I want to initialize slot with some data structure like a
> list, but I want the object to take the list and turn it into a hash
> table.

There is no direct mean to do what you want but you can write an
initialize method for your class. For instance

(define-method initialize ((self <foo>) initargs)
   (next-method) ;; do the normal initialization stuff
   (when (slot-bound? self 'slot)
       (set! (slot self) (* 2 (slot self)))))

This method will be automatically be called when the object is built
and will replace the value given by the user (if any) by its double.


                -- Erick
Received on Thu Mar 11 1999 - 21:41:28 CET

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