wl

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

commit 041254aceea82871d3a0ad9febdf8fb4b0f4415a
parent 79c81197b4023c9861f0655be2ebd0c23cc9e9a6
Author: tomas <tomas@logand.com>
Date:   Thu,  8 Oct 2009 22:09:58 +0200

added: let, use, prin, pack

Diffstat:
Mwl.java | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+), 0 deletions(-)

diff --git a/wl.java b/wl.java @@ -525,6 +525,34 @@ class wl implements Runnable { } return Z; }}); + fn("prin", new Fn() {public Any fn(Any E) { + PrintStream S = (PrintStream) Out.val().cxr(); + Any Z = NIL; + int I = 0; + for(Any X = E.cdr(); NIL != X; X = X.cdr()) { + if(0 < I++) S.print(' '); + Z = eval(X.car()); + prin(Z); + } + return Z; + }}); + fn("pack", new Fn() {public Any fn(Any E) { + ByteArrayOutputStream B = new ByteArrayOutputStream(); + PrintStream S = new PrintStream(B); + Any O = Out.val(); + Out.val(mkObj(S)); + for(Any X = E.cdr(); NIL != X; X = X.cdr()) + prin(eval(X.car())); + Out.val(O); + String Z = null; + try { + Z = B.toString(Enc); + S.close(); + } catch(UnsupportedEncodingException e) { + err(E, "Unsupported encoding " + Enc); + } + return mkObj(Z); + }}); // fn("in", new Fn() {public Any fn(Any E) { // Any X = E.cdr; @@ -635,6 +663,72 @@ class wl implements Runnable { Any X = eval(E.cdr().car()); return X.isCons() ? X : NIL; }}); + fn("let", new Fn() {public Any fn(Any E) { + Any Z = NIL; + Any I = E.cdr(); + Any L = I.car(); + if(L.isCons()) { + Any A = L; + Any B = mkCons(NIL, NIL); + Any C = B; + while(A.isCons()) { + Any K = A.car(); + A = A.cdr(); + Any V = eval(A.car()); + A = A.cdr(); + C.cdr(mkCons(K.val(), NIL)); + C = C.cdr(); + K.val(V); + } + Z = xrun(I.cdr()); + A = L; + C = B.cdr(); + while(A.isCons()) { + Any K = A.car(); + A = A.cdr().cdr(); + K.val(C.car()); + C = C.cdr(); + } + } else if(L.isIsym()) { + I = I.cdr(); + Any V = eval(I.car()); + Any O = L.val(); + L.val(V); + Z = xrun(I.cdr()); + L.val(O); + } else err(E, "Don't know how to let"); + return Z; + }}); + fn("use", new Fn() {public Any fn(Any E) { + Any Z = NIL; + Any I = E.cdr(); + Any L = I.car(); + if(L.isCons()) { + Any A = L; + Any B = mkCons(NIL, NIL); + Any C = B; + while(A.isCons()) { + Any K = A.car(); + A = A.cdr(); + C.cdr(mkCons(K.val(), NIL)); + C = C.cdr(); + } + Z = xrun(I.cdr()); + A = L; + C = B.cdr(); + while(A.isCons()) { + Any K = A.car(); + A = A.cdr(); + K.val(C.car()); + C = C.cdr(); + } + } else if(L.isIsym()) { + Any O = L.val(); + Z = xrun(I.cdr()); + L.val(O); + } else err(E, "Don't know how to let"); + return Z; + }}); fn("jnew", new Fn() {public Any fn(Any E) { // jnew 'cls [arg ...] Any I = E.cdr(); @@ -739,6 +833,21 @@ class wl implements Runnable { S.print(']'); } else err(E, "Don't know how to print"); } + Any prin(Any E) { + PrintStream S = (PrintStream) Out.val().cxr(); + if(NIL == E); + else if(E.isCons()) { + Any X = E; + while(X.isCons()) { + prin(X.car()); + X = X.cdr(); + } + prin(X); + } else if(E.isIsym()) S.print(E.nm()); + else if(E.isObj()) S.print(E.cxr()); + else err(E, "Don't know how to print"); + return E; + } String str(Any E) { ByteArrayOutputStream B = new ByteArrayOutputStream();