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


> I oppose "dynamic" setf! because I don't like the combination of being
> an elementary operation (storing a value in a location) and being hard
> to compile to efficient code.

It is quite easy to compile extended set! to efficient code.
You just have an slot associated with each procedure, and
generate code to extract and call the setter procedure in that slot.
One extra indirection for a setter call is quite reasonable in the
scheme of Scheme.

Also, I don't see that "storing a value in a location" is an
"elementary operation".  Storing a value in a data structure
(the main use of extended set!) can be quite complicated.
Even storing a value in a simple variable can be rather
complicated when you have to deal with closure analysis,
or thread-local (fluid) variable.

> I suppose you use
> (set! (setter foo) foo-setter)
> to set the setter of a procedure.

You could.  It would probably not be my recommended way for people
to do it.

> How do you propose that we tell the compiler that the binding between
> foo and foo-setter hereafter is read-only?

One possibility:

(define-settable foo
   (lambda (args ...) ...)
   (lambda (rhs args ...) ...))

which would be syntactic sugar for:

(define foo
  (bind-settable-pair
    (lambda (args ...) ...) 
    (lambda (rhs args ...) ...)))

where bind-settable-pair creates a new procedure object containing
the specified getter and setter actions.

A more general mechanism:

(define foo
  (make-procedure
     action: (lambda (args ...) ...)
     setter: (lambda (rhs args ...) ...)
     print-name: 'foo
     ... other attributes ...))

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner