From 98c581f95a71b06b6c83bc6e0dbfcdeb25e81864 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Mon, 26 Nov 2018 16:18:53 -0800 Subject: [PATCH] Jet +jab:by, which is used extensively in ford. --- include/jets/w.h | 1 + jets/d/by_jab.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ jets/tree.c | 3 +++ meson.build | 1 + 4 files changed, 61 insertions(+) create mode 100644 jets/d/by_jab.c diff --git a/include/jets/w.h b/include/jets/w.h index 578934703c..d8b5d8017e 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -84,6 +84,7 @@ u3_noun u3wdb_get(u3_noun); u3_noun u3wdb_has(u3_noun); u3_noun u3wdb_int(u3_noun); + u3_noun u3wdb_jab(u3_noun); u3_noun u3wdb_put(u3_noun); # define u3wdb_tap u3wdi_tap u3_noun u3wdb_uni(u3_noun); diff --git a/jets/d/by_jab.c b/jets/d/by_jab.c new file mode 100644 index 0000000000..f147232a21 --- /dev/null +++ b/jets/d/by_jab.c @@ -0,0 +1,56 @@ +/* j/4/by_jab.c +** +*/ +#include "all.h" + + +/* functions +*/ + u3_noun + u3qdb_jab(u3_noun a, + u3_noun key, + u3_noun fun) + { + if ( u3_nul == a ) { + return u3m_bail(c3__exit); + } + else { + u3_noun l_a, n_a, r_a; + u3_noun pn_a, qn_a; + + if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) || + (c3n == u3r_cell(n_a, &pn_a, &qn_a) ) ) + { + return u3m_bail(c3__exit); + } + else { + if ( (c3y == u3r_sing(key, pn_a)) ) { + u3_noun value = u3n_slam_on(u3k(fun), u3k(qn_a)); + return u3nc(u3nc(u3k(pn_a), value), u3k(u3t(a))); + } + else { + if ( c3y == u3qc_gor(key, pn_a) ) { + return u3nt(u3k(n_a), u3qdb_jab(l_a, key, fun), u3k(r_a)); + } + else { + return u3nt(u3k(n_a), u3k(l_a), u3qdb_jab(r_a, key, fun)); + } + } + } + } + } + + u3_noun + u3wdb_jab(u3_noun cor) + { + u3_noun a, key, fun; + + if ( c3n == u3r_mean(cor, u3x_sam_2, &key, + u3x_sam_3, &fun, + u3x_con_sam, &a, 0) ) { + return u3m_bail(c3__exit); + } else { + u3_noun n = u3qdb_jab(a, key, fun); + return n; + } + } diff --git a/jets/tree.c b/jets/tree.c index 57f21979ba..4facf4fa09 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -922,6 +922,8 @@ static c3_c* _141_two__in_ha[] = {0}; // static u3j_harm _141_two__by_int_a[] = {{".2", u3wdb_int, c3y}, {}}; // static c3_c* _141_two__by_int_ha[] = {0}; + static u3j_harm _141_two__by_jab_a[] = {{".2", u3wdb_jab, c3y}, {}}; + static c3_c* _141_two__by_jab_ha[] = {0}; static u3j_harm _141_two__by_put_a[] = {{".2", u3wdb_put, c3y}, {}}; static c3_c* _141_two__by_put_ha[] = {0}; static u3j_harm _141_two__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}}; @@ -938,6 +940,7 @@ static u3j_core _141_two__by_d[] = { "get", 7, _141_two__by_get_a, 0, _141_two__by_get_ha }, { "has", 7, _141_two__by_has_a, 0, _141_two__by_has_ha }, // { "int", 7, _141_two__by_int_a, 0, _141_two__by_int_ha }, + { "jab", 7, _141_two__by_jab_a, 0, _141_two__by_jab_ha }, { "put", 7, _141_two__by_put_a, 0, _141_two__by_put_ha }, { "tap", 7, _141_two__by_tap_a, 0, _141_two__by_tap_ha }, // { "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha }, diff --git a/meson.build b/meson.build index 5a1ac36c1e..405bd0d506 100644 --- a/meson.build +++ b/meson.build @@ -94,6 +94,7 @@ jets_d_src = [ 'jets/d/by_get.c', 'jets/d/by_has.c', 'jets/d/by_int.c', +'jets/d/by_jab.c', 'jets/d/by_put.c', 'jets/d/by_uni.c', 'jets/d/by_bif.c',