This is the mail archive of the guile@sourceware.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: Suggestion for strings.c



[I hope the following makes my point clear]

Per Bothner <per@bothner.com> writes:
> A "getter" returns the *contents* of a location, and set! changes the
> (contents of) this location.

Michael Livshin <mlivshin@bigfoot.com> writes:
> you set the setter to set-validate-counter-value, 
> et voila.

I would not complain if that were the case.  But, as Michael
already mentioned, it isn't.

As I understand the SRFI, for an object O written by some innocent user
there must be a setter which changes the (contents of) (some) location.
Who provides this setter, the user who has written O or the system?

From the SRFI:
"Each procedure that may be used as the first operand to set! must have
a corresponding "setter" procedure. The builtin procedure setter takes
a procedure and returns the corresponding setter procedure."

Who protects the user from not only changing the location
unconditionally (type 4) but from checking the arguments (type 3)?


> >     1 not exported at all
> > 
> >     2 immutable
> > 
> >     3 mutable but specified modification (see set-validate-counter-value)
> > 
> >     4 mutable


Per Bothner <per@bothner.com> writes:
> A "getter" returns the *contents* of a location, and set! changes the
> (contents of) this location.

That means that generalized set! can only operate on type 4 locations and
the setter must be provided by the system.  But then:

From the sample implementation (by Lars Thomas Hansen):

(define setter 
  (let ((setters (list (cons car  set-car!)
                       (cons cdr  set-cdr!)
                       (cons caar (lambda (p v) (set-car! (car p) v)))
                       (cons cadr (lambda (p v) (set-car! (cdr p) v)))
                       (cons cdar (lambda (p v) (set-cdr! (car p) v)))
                       (cons cddr (lambda (p v) (set-cdr! (cdr p) v)))
                       (cons vector-ref vector-set!)
                       (cons string-ref string-set!))))
    (letrec ((setter
              (lambda (proc)
                (let ((probe (assv proc setters)))
                  (if probe
                      (cdr probe)
                      (error "No setter for " proc)))))
             (set-setter!
              (lambda (proc setter)
                (set! setters (cons (cons proc setter) setters))
                (unspecified))))
      (set-setter! setter set-setter!)
      setter)))

How can the system guess how a setter for (say) "mb-string" should
look like?  The implementor of mb-string can't provide a setter since
you can't force him to follow your specification and provide a type 4
setter.  To quote the sentence again:


> A "getter" returns the *contents* of a location, and set! changes the
> (contents of) this location.

I conclude that it is not possible to implement your SRFI without
c-level support.  Lars' implementation does not do what you want.


Jost

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