01: // Copyright (c) 2005 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /** A Procedure that evaluates to the value of a Location.
07: * Calling it with one argument sets the value, for compatibility
08: * with the "parameter objects" of SRFI-39.
09: */
10: public class LocationProc extends Procedure0or1 implements HasSetter {
11: Location loc;
12:
13: public LocationProc(Location loc) {
14: this .loc = loc;
15: }
16:
17: public static LocationProc makeNamed(Symbol name, Location loc) {
18: LocationProc lproc = new LocationProc(loc);
19: lproc.setSymbol(name);
20: return lproc;
21: }
22:
23: public LocationProc(Location loc, Procedure converter) {
24: this .loc = loc;
25: if (converter != null)
26: pushConverter(converter);
27: }
28:
29: public void pushConverter(Procedure converter) {
30: loc = ConstrainedLocation.make(loc, converter);
31: }
32:
33: public Object apply0() throws Throwable {
34: return loc.get();
35: }
36:
37: public Object apply1(Object value) throws Throwable {
38: set0(value);
39: return Values.empty;
40: }
41:
42: public void set0(Object value) throws Throwable {
43: loc.set(value);
44: }
45:
46: public Procedure getSetter() {
47: return new Setter0(this );
48: }
49:
50: public final Location getLocation() {
51: return loc;
52: }
53:
54: public String toString() {
55: Object n = getSymbol();
56: if (n != null)
57: return super .toString();
58: return "#<location-proc " + loc + ">";
59: }
60: }
|