(guile.info.gz) Procedures with Setters
Info Catalog
(guile.info.gz) Procedure Properties
(guile.info.gz) Procedures and Macros
(guile.info.gz) Macros
23.4 Procedures with Setters
============================
A "procedure with setter" is a special kind of procedure which normally
behaves like any accessor procedure, that is a procedure which accesses
a data structure. The difference is that this kind of procedure has a
so-called "setter" attached, which is a procedure for storing something
into a data structure.
Procedures with setters are treated specially when the procedure
appears in the special form `set!' (REFFIXME). How it works is best
shown by example.
Suppose we have a procedure called `foo-ref', which accepts two
arguments, a value of type `foo' and an integer. The procedure returns
the value stored at the given index in the `foo' object. Let `f' be a
variable containing such a `foo' data structure.(1)
(foo-ref f 0) => bar
(foo-ref f 1) => braz
Also suppose that a corresponding setter procedure called `foo-set!'
does exist.
(foo-set! f 0 'bla)
(foo-ref f 0) => bla
Now we could create a new procedure called `foo', which is a
procedure with setter, by calling `make-procedure-with-setter' with the
accessor and setter procedures `foo-ref' and `foo-set!'. Let us call
this new procedure `foo'.
(define foo (make-procedure-with-setter foo-ref foo-set!))
`foo' can from now an be used to either read from the data structure
stored in `f', or to write into the structure.
(set! (foo f 0) 'dum)
(foo f 0) => dum
-- Scheme Procedure: make-procedure-with-setter procedure setter
-- C Function: scm_make_procedure_with_setter (procedure, setter)
Create a new procedure which behaves like PROCEDURE, but with the
associated setter SETTER.
-- Scheme Procedure: procedure-with-setter? obj
-- C Function: scm_procedure_with_setter_p (obj)
Return `#t' if OBJ is a procedure with an associated setter
procedure.
-- Scheme Procedure: procedure proc
-- C Function: scm_procedure (proc)
Return the procedure of PROC, which must be either a procedure
with setter, or an operator struct.
-- Scheme Procedure: setter proc
Return the setter of PROC, which must be either a procedure with
setter or an operator struct.
---------- Footnotes ----------
(1) Working definitions would be:
(define foo-ref vector-ref)
(define foo-set! vector-set!)
(define f (make-vector 2 #f))
Info Catalog
(guile.info.gz) Procedure Properties
(guile.info.gz) Procedures and Macros
(guile.info.gz) Macros
automatically generated byinfo2html