01: package gnu.mapping;
02:
03: /** A Procedure that can be used on the left-hand-side of an assignment.
04: * It can do that by overriding getSetter.
05: * Alternatively, it can use the default getSetter, as long as it
06: * overrides one of set0 (if a 0-argument Procedure)
07: * set1 (if a 1-argument Procedure), or setN (otherwise).
08: */
09:
10: public interface HasSetter {
11: public Procedure getSetter();
12: };
13:
14: /*
15: (define-syntax set!
16: (syntax-rules ()
17: ((set! (func arg ...) rhs)
18: ((setter func) arg ... rhs))
19: ((set! var rhs)
20: (%set! var rhs))))
21:
22: Better code generation:
23:
24: (apply (setter f) rhs args ...)
25: => f.set(rhs args ...)
26: E.g.
27: (set (f) rhs) => [compile f].set0([compile rhs])
28: (set (f x) rhs) => [compile f].set1([compile x], [compile rhs])
29: (set (f x1 .. xn) rhs)
30: => [compile f].setN([[compile x1], .. [compile xn], [compile rhs]])
31:
32: Examples:
33: (setter car) == set-car!
34: (setter cdr) == set-cdr!
35: (setter caXXXr) == (lambda (rhs pair) (set-car! (cXXXr pair) rhs)) ???
36: (setter cdXXXr) == (lambda (rhs pair) (set-cdr! (cXXXr pair) rhs)) ???
37: (setter list-ref) ...
38:
39: (ENV 'NAME) => value of NAME in ENV
40: (set! (ENV 'NAME) VAL) => set value of NAME in ENV to VAL
41:
42: (CELL) => current value of CELL
43: (set! (CELL) VALUE) => set value of CELL to VALUE
44: */
|