This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: setf.scm



mdj@nada.kth.se writes:
> Maciej Stachowiak <mstachow@MIT.EDU> writes:
> 
> > I think a purely dynamic one would be more in the spirit of Scheme.
> 
> I tend to agree.
> 
> In STk, (setter car) is treated as a variable name in some places.
> But since, you can't do things like
> 
>   (let (((setter car) set-car!)) ...)
> 
> and since the syntax
> 
>   (define (setter x) ...)
> 
> becomes very ambiguous, the idea is a bit unschemey.
> 

Yes, Common Lisp tries to do that and it actually kind of works due to
the different defun syntax and the separate function and variable
namespaces, but it would look ugly in Scheme.


> But, what I can't accept with the dynamic setf! is that it would be
> difficult to compile to efficient code.
> 
> Note that the use of setf! is an elementary operation in Goops (the
> Guile object system).  It should be efficient.  It is unacceptable to
> go looking into property lists at each use of a slot setter.
> 

It definitely should be efficient. I think the right thing to do is to
add an extra setter slot to procedure objects and write fast `setter'
and `set-setter!' implementations in C. I hypothesize this will make
the overhead unnoticable for interpreted code. 

For compiled code, there might be a noiticable penalty, but I don't
expect it to be critical, especially if the compiler can inline
`setter'. After all, when we move to generational GC the write barrier
will already add more overheads to write than that.


> The reason why I added setf! to guile-core was that the STk slot
> option #:accessor <name> creates the accessors <name> and (setter
> <name) for the slot.
> 
> Now I'm thinking of letting #:accessor <name> create the accessors
> <name> and set-<name>! instead.
> 
> Example:
> 
>   (define-class <c> ()
>     ((x #:accessor x)))
> 
>   (define o (make <c>))
> 
>   (set-x! o 1)
>   (x o) --> 1
> 
> That is reasonably schemey and is easier to compile to efficient code.
> 
> If I make this change, I want to remove setf! from guile-core.  It can
> be supplied as a separate package.
> 
> Opinions?
> 

I think it would be useful to have setf! in the Guile core anyway even
if this change were made, but a dynamic one. setf! is useful for many
things.

I also think that adding a special setter slot to procedure objects
would make performance good enough in practice that this change should
be unnecessary.

 - Maciej Stachowiak