Re: initialize slots without a modifier?
"Scott G. Miller" <[email protected]> Sun, 21 Oct 2007 08:49:02 -0500
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
On 10/20/07, Mike J. Bell <[email protected]> wrote: > I apologize if this hits the sisc-users list thrice; it hasn't shown up > (twice) for two days so I'm retrying... > > > In the SSS manual chapter 7, there are examples of making slots with > accessors and modifiers: > > (define-generics :x :y :y!) > (define-class (<foo>)) > (define-class (<bar>)) > (define-class (<baz> <foo> <bar>) > (x :x) > (y :y :y!)) > > Then later, the procedure for initialization ("constructor") is explained: > > (define-generics :x :x!) > (define-class (<baz>) > (x :x :x!)) > (define-method (initialize (<baz> b) (<number> x)) (:x! b x)) > (define baz (make <baz> 2)) > (:x baz) ;=> 2 > > So what I don't understand is how you would ever modify your slots in > initialize if you didn't create a modifier? Like, in the first > example, x only has an accessor. How do I set it? Is it constant, or > unbound? > If a class contains a slot that doesn't have a modifier, you can still modify it using the direct slot accessors described here: http://sisc-scheme.org/manual/html/ch07.html#OOSlots > I would imagine that the slot descriptor in the define-class specifies > what slots an object has and then their visibility; i.e. in the > following > > (define-generics :y :z :z!) > (define-class (<foobar>) > (x) > (y :y) > (z :z :z!)) > > x is for internal use only, y can be accessed but not modified, z is > read-write (in general, for clients). Mostly accessors and modifiers produce a shorthand way to defined them on the class, avoiding the lower level slot API. They are are also generics, so you can have an accessor which operates on more than one class, while the slot API accesses only the slots for a particular class. > P.S. It might be nice to update the documentation with more > real-world examples, i.e. instead of <foo> and <bar> make like a > simple <queue> or <stack> class that people can relate to better. If you'd like to file a bug related to that, it'll help remind us to update those docs for future releases. Thanks! Scott ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/