KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > HasSetter


1 package gnu.mapping;
2
3 /** A Procedure that can be used on the left-hand-side of an assignment.
4   * It can do that by overriding getSetter.
5   * Alternatively, it can use the default getSetter, as long as it
6   * overrides one of set0 (if a 0-argument Procedure)
7   * set1 (if a 1-argument Procedure), or setN (otherwise).
8   */

9
10 public interface HasSetter
11 {
12   public Procedure getSetter();
13 };
14
15 /*
16 (define-syntax set!
17  (syntax-rules ()
18   ((set! (func arg ...) rhs)
19    ((setter func) arg ... rhs))
20   ((set! var rhs)
21    (%set! var rhs))))
22
23 Better code generation:
24
25 (apply (setter f) rhs args ...)
26 => f.set(rhs args ...)
27 E.g.
28 (set (f) rhs) => [compile f].set0([compile rhs])
29 (set (f x) rhs) => [compile f].set1([compile x], [compile rhs])
30 (set (f x1 .. xn) rhs)
31     => [compile f].setN([[compile x1], .. [compile xn], [compile rhs]])
32
33 Examples:
34 (setter car) == set-car!
35 (setter cdr) == set-cdr!
36 (setter caXXXr) == (lambda (rhs pair) (set-car! (cXXXr pair) rhs)) ???
37 (setter cdXXXr) == (lambda (rhs pair) (set-cdr! (cXXXr pair) rhs)) ???
38 (setter list-ref) ...
39
40 (ENV 'NAME) => value of NAME in ENV
41 (set! (ENV 'NAME) VAL) => set value of NAME in ENV to VAL
42
43 (CELL) => current value of CELL
44 (set! (CELL) VALUE) => set value of CELL to VALUE
45 */

46
Popular Tags