diff --git a/include/jets/k.h b/include/jets/k.h index 3edde2142..0d06a9a64 100644 --- a/include/jets/k.h +++ b/include/jets/k.h @@ -43,6 +43,11 @@ u3_noun u3kc_rip(u3_atom a, u3_atom b); + /* u3kc_swp(): reverse block order. + */ + u3_noun + u3kc_swp(u3_atom a, u3_atom b); + /* u3kd: tier 4 functions */ /* u3kdb_get(): map get for key `b` in map `a` with u3_none. diff --git a/include/jets/q.h b/include/jets/q.h index 48db0ea5e..6a7763a85 100644 --- a/include/jets/q.h +++ b/include/jets/q.h @@ -66,6 +66,7 @@ u3_noun u3qc_rep(u3_atom, u3_noun); u3_noun u3qc_rip(u3_atom, u3_atom); u3_noun u3qc_rsh(u3_atom, u3_atom, u3_atom); + u3_noun u3qc_swp(u3_atom, u3_atom); u3_noun u3qc_sqt(u3_atom); u3_noun u3qc_vor(u3_atom, u3_atom); diff --git a/include/jets/w.h b/include/jets/w.h index 693cff4ba..0993ab563 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -66,6 +66,7 @@ u3_noun u3wc_rep(u3_noun); u3_noun u3wc_rip(u3_noun); u3_noun u3wc_rsh(u3_noun); + u3_noun u3wc_swp(u3_noun); u3_noun u3wc_sqt(u3_noun); u3_noun u3wc_vor(u3_noun); diff --git a/jets/c/swp.c b/jets/c/swp.c new file mode 100644 index 000000000..1b10dca2b --- /dev/null +++ b/jets/c/swp.c @@ -0,0 +1,39 @@ +/* j/3/swp.c +** +*/ +#include "all.h" + +/* functions +*/ + + u3_noun + u3qc_swp(u3_atom a, + u3_atom b) + { + //XX write a proper c-style swp, maybe + return u3kc_rep(u3k(a), u3kb_flop(u3qc_rip(a, b))); + } + + u3_noun + u3wc_swp(u3_noun cor) + { + u3_noun a, b; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + (c3n == u3ud(a)) || + (c3n == u3ud(b)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qc_swp(a, b); + } + } + + u3_noun + u3kc_swp(u3_atom a, + u3_atom b) + { + u3_noun res = u3qc_swp(a, b); + u3z(a); u3z(b); + return res; + } diff --git a/jets/tree.c b/jets/tree.c index 784ae0607..e82317c87 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -512,6 +512,7 @@ static u3j_core _143_tri_d[] = static u3j_harm _143_two_rep_a[] = {{".2", u3wc_rep, c3y}, {}}; static u3j_harm _143_two_rip_a[] = {{".2", u3wc_rip, c3y}, {}}; static u3j_harm _143_two_rsh_a[] = {{".2", u3wc_rsh, c3y}, {}}; + static u3j_harm _143_two_swp_a[] = {{".2", u3wc_swp, c3y}, {}}; static u3j_harm _143_two_sqt_a[] = {{".2", u3wc_sqt, c3y}, {}}; static u3j_harm _143_two_vor_a[] = {{".2", u3wc_vor, c3y}, {}}; static u3j_harm _143_two_xeb_a[] = {{".2", u3wc_xeb, c3y}, {}}; @@ -618,12 +619,14 @@ static u3j_core _143_two_d[] = { "rub", _143_two_rub_a }, { "peg", _143_two_peg_a }, { "pow", _143_two_pow_a }, + { "swp", _143_two_swp_a }, { "sqt", _143_two_sqt_a }, { "vor", _143_two_vor_a }, { "xeb", _143_two_xeb_a }, { "by", 0, _143_two__by_d }, { "in", 0, _143_two__in_d }, + {} }; diff --git a/meson.build b/meson.build index e89ab0793..772c84c63 100644 --- a/meson.build +++ b/meson.build @@ -73,6 +73,7 @@ jets_c_src = [ 'jets/c/rep.c', 'jets/c/rip.c', 'jets/c/rsh.c', +'jets/c/swp.c', 'jets/c/sqt.c', 'jets/c/vor.c', ]