wl

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

commit ca99dd99deb84fdb5175d5460ba0fdc431534612
parent 1c4cdc19b99423e1415a1e4a2c42b1d3401e0c00
Author: tomas <tomas@logand.com>
Date:   Sun, 25 Oct 2009 16:11:57 +0100

up. up fully implemented

Diffstat:
Mwl.java | 48++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/wl.java b/wl.java @@ -947,46 +947,66 @@ class wl implements Runnable { } else err(E, "Don't know how to let"); return Z; }}); - fn("up", new Fn() {public Any fn(Any E) { // TODO cnt frame up + fn("up", new Fn() {public Any fn(Any E) { // (up [cnt] sym ['val]) Any Z; Any I = E.cdr(); Any K = I.car(); I = I.cdr(); - if(I.isCons()) { // (up K 'Z) + int n = 1; + if(K.isOnum()) { + n = ((BigInteger) K.obj()).intValue(); + K = I.car(); + I = I.cdr(); + } + if(I.isCons()) { // set Z = eval(I.car()); boolean done = false; - for(Any J = Env.val(); J.isCons() && T != J.car(); J = J.cdr()) { + for(Any J = Env.val(); J.isCons(); J = J.cdr()) { Any C = J.car(); - if(K == C.car()) {C.cdr(Z); done = true; break;} + if(T == C) {n--; continue;} + if(n < 1) break; + if(K == C.car()) {if(n <= 1) {C.cdr(Z); done = true; break;}} } if(!done) Env.val(mkCons(mkCons(K, Z), Env.val())); - } else { // (up K) + } else { // get Z = K.val(); - for(Any J = Env.val(); J.isCons() && T != J.car(); J = J.cdr()) { + for(Any J = Env.val(); J.isCons(); J = J.cdr()) { Any C = J.car(); - if(K == C.car()) {Z = C.cdr(); break;} + if(T == C) {n--; continue;} + if(n < 1) break; + if(K == C.car()) {Z = C.cdr(); if(n <= 1) break;} } } return Z; }}); - fn("up.", new Fn() {public Any fn(Any E) { // TODO cnt frame up + fn("up.", new Fn() {public Any fn(Any E) { // (up ['cnt] 'sym ['val]) Any Z; Any I = E.cdr(); Any K = eval(I.car()); I = I.cdr(); - if(I.isCons()) { // (up 'K 'Z) + int n = 1; + if(K.isOnum()) { + n = ((BigInteger) K.obj()).intValue(); + K = eval(I.car()); + I = I.cdr(); + } + if(I.isCons()) { // set Z = eval(I.car()); boolean done = false; - for(Any J = Env.val(); J.isCons() && T != J.car(); J = J.cdr()) { + for(Any J = Env.val(); J.isCons(); J = J.cdr()) { Any C = J.car(); - if(K == C.car()) {C.cdr(Z); done = true; break;} + if(T == C) {n--; continue;} + if(n < 1) break; + if(K == C.car()) {if(n <= 1) {C.cdr(Z); done = true; break;}} } if(!done) Env.val(mkCons(mkCons(K, Z), Env.val())); - } else { // (up 'K) + } else { // get Z = K.val(); - for(Any J = Env.val(); J.isCons() && T != J.car(); J = J.cdr()) { + for(Any J = Env.val(); J.isCons(); J = J.cdr()) { Any C = J.car(); - if(K == C.car()) {Z = C.cdr(); break;} + if(T == C) {n--; continue;} + if(n < 1) break; + if(K == C.car()) {Z = C.cdr(); if(n <= 1) break;} } } return Z;