wl

Unnamed repository; edit this file 'description' to name the repository.
git clone https://logand.com/git/wl.git/
Log | Files | Refs | LICENSE

commit 881b6d907563422acbf2f6b37a19f0d7ebcedb95
parent b2a3478a834c4e8127e34dd0d3526bd263fc9899
Author: tomas <tomas@logand.com>
Date:   Sat,  7 Nov 2009 01:07:20 +0100

cons2 jvector fix, added lit pwd dir info; jeq fix, added jv2l, err w/exception message

Diffstat:
Mjava.wl | 30+++++++++++++++++++++++++++---
Mwl.java | 32+++++++++++++++++++++++++++-----
2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/java.wl b/java.wl @@ -168,7 +168,7 @@ (de unfoldr (P F G X E) (if (P X) E (cons2 (F X) (unfoldr P F G (G X))))) # TODO loop (de hylo (P F G E H X) (if (P X) E (hylo P F G (H (F X) E) H (G X)))) # TODO loop (de constantly (X) (list NIL (cons2 'quote X))) -(de fmap (F L) (foldlx '((X Y) (cons2 ((eval 'F 2) (car Y)))) NIL L)) # TODO use up +(de fmap (F L) (foldlx '((X Y) (cons2 ((up F 2) (car Y)))) NIL L)) # TODO use up (de o @ (list (list 'X) (foldr '((F X) (list F X)) 'X (rest)))) (de oq L (list (list 'X) (foldr '((F X) (list F X)) 'X L))) @@ -180,7 +180,9 @@ (de need (N L S) (unfoldl =0 (constantly S) 1- N)) # TODO L, -N (de cons @ - (foldlx '((X Y) (if (pair (cdr Y)) (cons2 (car Y) (cdr Y)) (car Y))) NIL (rest)) ) + (cons2 (next) + (foldlx '((X Y) (if (pair (cdr Y)) (cons2 (car Y) (cdr Y)) (car Y))) + NIL (rest) ) ) ) (de and L (loop @@ -483,7 +485,29 @@ #(de exec () (`((jclass 'java.lang.Runtime) 'getRuntime) 'gc)) (de jvector @ - (let X (jnew (jclass 'java.util.Vector)) + (let X (jnew `(jclass 'java.util.Vector)) (while (args) (X 'add (next)) ) X ) ) + +(de lit (X) (if (atom X) X (cons 'quote X))) + +(de pwd () (`(jclass 'java.lang.System) 'getProperty "user.dir")) + +#(de jv2l (X) +# (let (A (`(jclass 'java.util.Arrays) 'asList X) L (cons) M L) +# (unless (jeq true (A 'isEmpty)) +# (println A (A 'isEmpty)) +# (setq M (con M (cons (A 'remove 0) NIL))) ) +# (cdr L) ) ) + +(de dir (X) + (filter '((X) (unless (= "." (car (chop X))) X)) + (jv2l ((jnew `(jclass 'java.io.File) (or X ".")) 'list)) ) ) + +(de info (X) # TODO proper date & time + (let F (jnew `(jclass 'java.io.File) (or X ".")) + (and (jeq true (F 'exists)) + (cons (or (jeq true (F 'isDirectory)) (jnum (F 'length))) + (jnum (F 'lastModified)) + (jnum (F 'lastModified)) ) ) ) ) diff --git a/wl.java b/wl.java @@ -22,6 +22,8 @@ import java.lang.reflect.InvocationHandler; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; class wl implements Runnable { @@ -62,6 +64,12 @@ class wl implements Runnable { throw new RuntimeException(M + ": " + str((Any) X)); throw new RuntimeException(M + ": " + X); } + void err(Object X, Exception M) { + if(null != X && X instanceof Any) + throw + new RuntimeException(M + ":: " + M.getMessage() + ": " + str((Any) X)); + throw new RuntimeException(M + ": " + X); + } static void err(String M) {throw new RuntimeException(M);} static public interface Fn { @@ -575,9 +583,9 @@ class wl implements Runnable { Object r = m.invoke(o, methodArgs(m, aa)); Z = mkObj(r); } catch(IllegalAccessException e) { - err(E, "IllegalAccessException"); + err(E, e); } catch(InvocationTargetException e) { - err(E, "InvocationTargetException"); + err(E, e); } return Z; } @@ -1201,12 +1209,26 @@ class wl implements Runnable { fn("jeq", new Fn() {public Any fn(Any E) { Any I = E.cdr(); if(I.isCons()) { - Any X = eval(I.car()); - for(I = I.cdr(); I.isCons(); I = I.cdr()) - if(X.obj() != eval(I.car()).obj()) return NIL; + Object A = eval(I.car()).obj(); + for(I = I.cdr(); I.isCons(); I = I.cdr()) { + Object B = eval(I.car()).obj(); + if(Boolean.TRUE.equals(A)) { + if(!Boolean.TRUE.equals(B)) return NIL; + } else if(Boolean.FALSE.equals(A)) { + if(!Boolean.FALSE.equals(B)) return NIL; + } else if(A != B) return NIL; + } } return T; }}); + fn("jv2l", new Fn() {public Any fn(Any E) { // TODO in lisp! + Object[] x = (Object[]) eval(E.cdr().car()).obj(); + Any Z = NIL; + if(null != x) + for(int i = x.length - 1; 0 <= i; i--) + Z = mkCons(mkObj(x[i]), Z); + return Z; + }}); fn("wait", new Fn() {public Any fn(Any E) { // wait ['cnt] . prg Any Z = NIL; // TODO poll from Que with timeout cnt unless run(prg)