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: Setter argument order in getter-with-setters


Well, you can have a more complex transformation rule:

For example:
	(set! (PROC) NEWVAL) -> ((setter-0 PROC) NEWVAL)
	(set! (PROC ARG1) NEWVAL) -> ((setter-1 PROC) ARG1 NEWVAL)
	(set! (PROC ARG1 ARG2) NEWVAL) -> ((setter-2 PROC) ARG1 ARG2 NEWVAL)
	(set! (PROC ARG1 ARG2 ARG3 ...) NEWVAL) ->
		((setter-many PROC) NEWVAL ARG1 ARG2 ARG3 ...)

You also have to define default rules something like this:

(define-method (setter-0 proc)
   (lambda (newval) ((setter-many proc) newval)))
(define-method (setter-1 proc)
   (lambda (arg1 newval) ((setter-many proc) newval arg1)))
(define-method (setter-2 proc)
   (lambda (arg1 arg2 newval) ((setter-many proc) newval arg1 arg2)))

I actually do something approaching this in Kawa (using different virtual
methods), mainly to avoid creating copying argument lists.  Whether it is
worth it, I don't know.

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