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

setter again

I am anxious to see this setter thing resolved and I've been thinking
about it.

I have decided that the desire to hide the difference between setting
a slot and calling a method is fundamentally at odds with setter
syntax.  In other words, if one really wants the former, it must be
impossible to use the setter syntax on a slot from anywhere except
within the lexical scope of the class to which the slot belongs.

In other words, this should not be legal:

(set! (slot object) new-value)

This should be legal within the lexical scope of the object:

(set! slot new-value)

This is not as bad as it sounds because, the same name could be 
used for both a method and a value:

(method object) ; to get the value of 'method'

(method object new-value) ; to send a value to object via method.
			  ; The body of 'method' in this case may 
			  ; default to merely setting a slot.

This would also solve this problem:

(define-class <foo> (<object>)
;Value: <foo>

(define foo (make <foo>))
;Value: foo

(define-method set-foo (m (f <foo>) i)
  ((setter m) f i))	; currently this is literally translated as
			; (set! (m f) i) and method 'm' doesn't exist
;Value: set-foo

'set-foo' would be replaced with:

(define-method set-foo (m (f <foo>) i)
  (m f i))

I think in general, this simplifies the language and at the same time,
makes it more powerful.  It would be best if this was formalized in
the language itself, but I tried to achieve something similar within
the current language.  I ran into a problem.

Experiments in Thomas seem to show that a parameter list with a 
different number of arguments is considered illegal, although
I can't find anyplace in the Dylan manual that this is explicitly
stated.  For example:

(define-class <bar> (<object>)

(define-method item ((o <bar>))
  (item-slot o))

(define-method item ((o <bar>) new-value)	; pukes here
  (set! (item-slot o) new-value))

(define bar (make <bar>))

(item bar "hello")  ; should set item to "hello"

(item bar)	    ; should evaluate to the value of bar's item

Any input would be greatly appreciated.