[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about MzScheme Objects



Quoting "Alex Peake":
> (define attr<%> (interface () set-name! pk? set-pk!))
> 
> (define attr%
>   (class* object% (attr<%>) (attr-name (pk #f) (fk #f))
>     (public
>       (domain 'integer)
>       (name attr-name)
>       (set-name! (lambda (attr-name) (set! name attr-name)))
>       (pk? (lambda () pk))
>       (set-pk! (lambda (is-pk) (set! pk is-pk)))
>       (fk? (lambda () fk)))
>     (sequence (super-init))))
> 
> 1) why is there an instance variable fk (and not an instance variable
> attr-name)(or maybe there is)?

Yes, there's a private `attr-name' nstance variable. Neither `fk' nor
`attr-name' are accessible from outside the class:

 > (define o (make-object attr% 'hi))
 > (ivar o fk)
 ivar: instance variable not found: fk in class: attr%

but `fk' and `attr-name' are both bound within the body of the `class'
expression.

> 2) is there a way to default pk and yet set fk?

Not in 103.X.

In the new class system of v200, initalization arguments can be
provided by name, so they can be specified individually and in any
order.

> 3) why is fk? not required in the interface?

As in Java, an interface determines a minimal set of methods, but an
implementing class can have extra methods (and usually does).

Matthew