wl

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

commit 705745a59e9e838193c1c0a35feb97b6f121d0f1
parent ece72e5ae3a5298045be26bff225d3d6ae28b10a
Author: tomas <tomas@logand.com>
Date:   Sun, 11 Oct 2009 14:22:26 +0200

=, ==, str?, num? impl; cond, nond + minor fixes

Diffstat:
Mjava.wl | 23+++++++++++++++++++----
Mwl.java | 35+++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/java.wl b/java.wl @@ -69,6 +69,21 @@ (pop 'L) (T T (run L 1)) ) ) +(de cond L + (use X + (loop + (NIL L) + (setq X (pop 'L)) + (T (eval (car X) 1) (up @ @) (run (cdr X) 1)) ) ) ) + +(de nond L + (use X + (loop + (NIL L) + (setq X (pop 'L)) + (NIL (eval (car X) 1) (run (cdr X) 1)) + (up @ @) ) ) ) + (de prog P (run P 1)) (de prog1 (E . P) (up @ E) (run P 1) E) (de prog2 (E F . P) (up @ F) (run P 1) F) @@ -153,7 +168,7 @@ (de jclass (N) (java.lang.Class 'forName N)) -(de gc () (((jclass 'java.lang.Runtime) 'getRuntime) 'gc)) +(de gc () (`((jclass 'java.lang.Runtime) 'getRuntime) 'gc)) (de import L (let (P (pop 'L) C) @@ -161,12 +176,10 @@ (setq C (pop 'L)) (def C (jclass (pack P "." C))) ) ) ) -(setq *Int (jclass 'java.math.BigInteger)) - (de - L (let? Z (eval (pop 'L) 1) (ifn L - ((jfield *Int 'ZERO) 'subtract Z) + (0 'subtract Z) (loop (NIL L Z) (setq Y (eval (pop 'L) 1)) @@ -196,3 +209,5 @@ (setq Y (eval (pop 'L) 1)) (NIL Y) (setq Z (Z 'reminder Y)) ) ) ) + +(de + @ (- (pass - 0))) diff --git a/wl.java b/wl.java @@ -480,6 +480,14 @@ class wl implements Runnable { } Env.val(X); } + boolean equal(Any X, Any Y) { + boolean z = true; + if(X.isCons()) z = equal(X.car(), Y.car()) && equal(X.cdr(), Y.cdr()); + else if(X.isSym()) z = Y.isSym() && X == Y; + else if(X.isObj()) z = Y.isObj() && X.obj().equals(Y.obj()); + else err("Don't know how to equal"); + return z; + } public wl() { Sd.put("NIL", NIL); @@ -543,8 +551,22 @@ class wl implements Runnable { } }}); fn("==", new Fn() {public Any fn(Any E) { - Any X = E.cdr(); - return eval(X.car()) == eval(X.cdr().car()) ? T : NIL; + Any I = E.cdr(); + if(I.isCons()) { + Any X = eval(I.car()); + for(I = I.cdr(); I.isCons(); I = I.cdr()) + if(X != eval(I.car())) return NIL; + } + return T; + }}); + fn("=", 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(!equal(X, eval(I.car()))) return NIL; + } + return T; }}); fn("peek", new Fn() {public Any fn(Any E) { Character X = peek(); @@ -657,8 +679,13 @@ class wl implements Runnable { return X.isCons() ? X : NIL; }}); fn("sym?", new Fn() {public Any fn(Any E) { - Any X = eval(E.cdr().car()); - return X.isSym() ? T : NIL; + return eval(E.cdr().car()).isSym() ? T : NIL; + }}); + fn("str?", new Fn() {public Any fn(Any E) { + return eval(E.cdr().car()).isOstr() ? T : NIL; + }}); + fn("num?", new Fn() {public Any fn(Any E) { + return eval(E.cdr().car()).isOnum() ? T : NIL; }}); fn("let", new Fn() {public Any fn(Any E) { Any Z = NIL;