commit f86dfaaa3be1cbaa747b10fe5430212211a720ad
parent 881b6d907563422acbf2f6b37a19f0d7ebcedb95
Author: tomas <tomas@logand.com>
Date: Sat, 7 Nov 2009 11:18:39 +0100
object get prop put ; : :: with asym box box? getl putl
Diffstat:
M | java.wl | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
M | wl.java | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
2 files changed, 97 insertions(+), 8 deletions(-)
diff --git a/java.wl b/java.wl
@@ -511,3 +511,48 @@
(cons (or (jeq true (F 'isDirectory)) (jnum (F 'length)))
(jnum (F 'lastModified))
(jnum (F 'lastModified)) ) ) ) )
+
+(de object (S C . @)
+ (set S C)
+ (while (args)
+ (put S (next) (next)) ) )
+
+(de get (S . @)
+ (while (args)
+ (let (K (next) L (getl S) C)
+ (loop
+ (NIL L (unless (args) (or (atom C) (car C))))
+ (T (and (atom (setq C (pop 'L))) (== K C)) (setq S T))
+ (T (and (pair C) (== K (cdr C))) (setq S (car C))) ) ) ) )
+
+(de prop (S K) # TODO argv
+ (let (L (getl S) C)
+ (loop
+ (NIL L)
+ (T (and (atom (setq C (pop 'L))) (== K C)) C)
+ (T (and (pair C) (== K (cdr C))) C) ) ) )
+
+(de put (S K V) # TODO argv
+ (if V
+ (let (L (getl S) C)
+ (loop
+ (NIL L (putl S (cons (cons V K) (getl S))))
+ (T (and (atom (setq C (car L))) (== K C)) (or (=T V) (set L (cons V K))))
+ (T (and (pair C) (== K (cdr C))) (if (=T V) (set L K) (set C V)))
+ (setq L (cdr L)) ) )
+ (putl S (filter '((C) (not (if (atom C) (== K C) (== K (cdr C))))) (getl S))) )
+ V )
+
+(de ; (S . P)
+ (while P
+ (let (K (pop 'P) L (getl S) C)
+ (loop
+ (NIL L (unless P (or (atom C) (car C))))
+ (T (and (atom (setq C (pop 'L))) (== K C)) (setq S T))
+ (T (and (pair C) (== K (cdr C))) (setq S (car C))) ) ) ) )
+
+#(de ; (S . L) (apply get L S))
+#(de : L (apply get L This))
+#(de :: (S . L) (apply prop L S)) # ???
+
+(de with (This . P) (run P 1 '(This)))
diff --git a/wl.java b/wl.java
@@ -91,6 +91,7 @@ class wl implements Runnable {
public boolean isCons();
public boolean isSym();
public boolean isIsym();
+ public boolean isAsym();
public boolean isObj();
public boolean isOfn();
public boolean isOstr();
@@ -114,6 +115,7 @@ class wl implements Runnable {
public boolean isCons() {return true;};
public boolean isSym() {return false;};
public boolean isIsym() {return false;};
+ public boolean isAsym() {return false;};
public boolean isObj() {return false;};
public boolean isOfn() {return false;};
public boolean isOstr() {return false;};
@@ -139,6 +141,31 @@ class wl implements Runnable {
public boolean isCons() {return false;};
public boolean isSym() {return true;};
public boolean isIsym() {return true;};
+ public boolean isAsym() {return false;};
+ public boolean isObj() {return false;};
+ public boolean isOfn() {return false;};
+ public boolean isOstr() {return false;};
+ public boolean isOnum() {return false;};
+ public boolean isOobj() {return false;};
+ }
+ static class Asym implements Sym {
+ public Any val, prop;
+ public Asym(Any v, Any p) {val = v; prop = p;}
+ public String nm() {err("No Asym.nm"); return null;}
+ public Any car() {err("No Asym.car"); return null;}
+ public Any cdr() {err("No Asym.cdr"); return null;}
+ public Any val() {return val;}
+ public Any prop() {return prop;}
+ public Object obj() {err("No Asym.obj"); return null;}
+ public Any car(Any a) {err("No Asym.car"); return null;}
+ public Any cdr(Any d) {err("No Asym.cdr"); return null;}
+ public Any val(Any v) {val = v; return val;}
+ public Any prop(Any p) {prop = p; return prop;}
+ public Object obj(Object x) {err("No Asym.obj"); return null;}
+ public boolean isCons() {return false;};
+ public boolean isSym() {return true;};
+ public boolean isIsym() {return false;};
+ public boolean isAsym() {return true;};
public boolean isObj() {return false;};
public boolean isOfn() {return false;};
public boolean isOstr() {return false;};
@@ -162,6 +189,7 @@ class wl implements Runnable {
public boolean isCons() {return false;};
public boolean isSym() {return false;};
public boolean isIsym() {return false;};
+ public boolean isAsym() {return false;};
public boolean isObj() {return true;};
public boolean isOfn() {return obj instanceof Fn;};
public boolean isOstr() {return obj instanceof String;};
@@ -171,6 +199,7 @@ class wl implements Runnable {
static Any mkCons(Any a, Any d) {return new Cons(a, d);}
static Any mkIsym(String n, Any v) {return new Isym(n, v, NIL);}
+ static Any mkAsym(Any v, Any p) {return new Asym(v, p);}
static Any mkObj(Object x) {return new Obj(x);}
static Any mkOint(String x) {return mkObj(new BigInteger(x));}
Any mkOfix(String x) {
@@ -691,11 +720,6 @@ class wl implements Runnable {
else err("Don't know how to lt");
return z;
}
- // Any box(Any X) {
- // Any Z = mkIsym(null, X);
- // Z.nm(Z.toString());
- // return Z;
- // }
final wl Wl = this;
final BlockingQueue<Any> Que = new LinkedBlockingQueue<Any>();
@@ -1125,7 +1149,12 @@ class wl implements Runnable {
}
return Z;
}});
- // fn("box", new Fn() {public Any fn(Any E) {return box(eval(E.cdr().car()));}});
+ fn("box", new Fn() {public Any fn(Any E) {
+ return mkAsym(eval(E.cdr().car()), NIL);
+ }});
+ fn("box?", new Fn() {public Any fn(Any E) {
+ return eval(E.cdr().car()).isAsym() ? T : NIL;
+ }});
fn("jnew", new Fn() {public Any fn(Any E) { // jnew 'cls [arg ...]
Any I = E.cdr();
Any C = eval(I.car());
@@ -1306,6 +1335,15 @@ class wl implements Runnable {
return Z == null ? NIL : Z;
}});
fn("eof", new Fn() {public Any fn(Any E) {return eof() ? T : NIL;}});
+ fn("getl", new Fn() {public Any fn(Any E) { // TODO !!!
+ return eval(E.cdr().car()).prop();
+ }});
+ fn("putl", new Fn() {public Any fn(Any E) { // TODO !!!
+ Any I = E.cdr();
+ Any X = eval(I.car());
+ Any L = eval(I.cdr().car());
+ return X.prop(L);
+ }});
}
class Exc extends RuntimeException {
@@ -1341,7 +1379,10 @@ class wl implements Runnable {
S.print(')');
}
} else if(E.isIsym()) S.print(E.nm());
- else if(E.isOnum()) S.print(E.obj());
+ else if(E.isAsym()) {
+ String n = E.toString();
+ S.print("$" + n.substring(1 + n.lastIndexOf("@")));
+ } else if(E.isOnum()) S.print(E.obj());
else if(E.isOstr()) {
S.print('"');
String X = (String) E.obj();
@@ -1369,7 +1410,10 @@ class wl implements Runnable {
}
prin(X);
} else if(E.isIsym()) S.print(E.nm());
- else if(E.isObj()) S.print(E.obj());
+ else if(E.isAsym()) {
+ String n = E.toString();
+ S.print("$" + n.substring(1 + n.lastIndexOf("@")));
+ } else if(E.isObj()) S.print(E.obj());
else err(E, "Don't know how to print");
return E;
}