1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-05 09:10:18 +02:00

(Slot Options): Added example from Ludovic Courtès

about difference between init-value, -form and -thunk.
This commit is contained in:
Neil Jerram 2006-09-28 07:55:05 +00:00
parent f0de8d290b
commit 5ce6ee75df
2 changed files with 39 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2006-09-28 Neil Jerram <neil@ossau.uklinux.net>
* goops.texi (Slot Options): Added example from Ludovic Courtès
about difference between init-value, -form and -thunk.
2006-04-21 Kevin Ryde <user42@zip.com.au> 2006-04-21 Kevin Ryde <user42@zip.com.au>
* hierarchy.pdf: New file, converted from hierarchy.eps using * hierarchy.pdf: New file, converted from hierarchy.eps using

View file

@ -838,8 +838,40 @@ value (shared across all new instances of the class).
when a new instance is created and should return the desired initial when a new instance is created and should return the desired initial
slot value. @var{init-form} is an unevaluated expression that gets slot value. @var{init-form} is an unevaluated expression that gets
evaluated when a new instance is created and should return the desired evaluated when a new instance is created and should return the desired
initial slot value. @var{init-keyword} is a keyword that can be used to initial slot value. @var{init-keyword} is a keyword that can be used
pass an initial slot value to @code{make} when creating a new instance. to pass an initial slot value to @code{make} when creating a new
instance.
Note that, since an @code{init-value} value is shared across all
instances of a class, you should only use it when the initial value is
an immutable value, like a constant. If you want to initialize a slot
with a fresh, independently mutable value, you should use
@code{init-thunk} or @code{init-form} instead. Consider the following
example.
@example
(define-class <chbouib> ()
(hashtab #:init-value (make-hash-table)))
@end example
@noindent
Here only one hash table is created and all instances of
@code{<chbouib>} have their @code{hashtab} slot refer to it. In order
to have each instance of @code{<chbouib>} refer to a new hash table, you
should instead write:
@example
(define-class <chbouib> ()
(hashtab #:init-thunk make-hash-table))
@end example
@noindent
or:
@example
(define-class <chbouib> ()
(hashtab #:init-form (make-hash-table)))
@end example
If more than one of these options is specified for the same slot, the If more than one of these options is specified for the same slot, the
order of precedence, highest first is order of precedence, highest first is