jets: +key:by and +wyt:by

This commit is contained in:
Elliot Glaysher 2020-05-07 17:12:22 -07:00
parent 7149e591ef
commit 3f293cae47
4 changed files with 49 additions and 3 deletions

View File

@ -1603,6 +1603,7 @@
d(l a(r l.d)) d(l a(r l.d))
:: ::
++ rep :: reduce to product ++ rep :: reduce to product
~/ %rep
|* b/_=>(~ |=({* *} +<+)) |* b/_=>(~ |=({* *} +<+))
|- |-
?~ a +<+.b ?~ a +<+.b
@ -1692,12 +1693,16 @@
a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a)) a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
:: ::
++ wyt :: depth of map ++ wyt :: depth of map
|- ^- @ =< $
~% %wyt + ~
|. ^- @
?~(a 0 +((add $(a l.a) $(a r.a)))) ?~(a 0 +((add $(a l.a) $(a r.a))))
:: ::
++ key :: set of keys ++ key :: set of keys
=< $
~/ %key
=+ b=`(set _?>(?=(^ a) p.n.a))`~ =+ b=`(set _?>(?=(^ a) p.n.a))`~
|- ^+ b |. ^+ b
?~ a b ?~ a b
$(a r.a, b $(a l.a, b (~(put in b) p.n.a))) $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
:: ::

View File

@ -86,10 +86,12 @@
u3_noun u3wdb_has(u3_noun); u3_noun u3wdb_has(u3_noun);
u3_noun u3wdb_int(u3_noun); u3_noun u3wdb_int(u3_noun);
u3_noun u3wdb_jab(u3_noun); u3_noun u3wdb_jab(u3_noun);
u3_noun u3wdb_key(u3_noun);
u3_noun u3wdb_put(u3_noun); u3_noun u3wdb_put(u3_noun);
# define u3wdb_tap u3wdi_tap # define u3wdb_tap u3wdi_tap
u3_noun u3wdb_uni(u3_noun); u3_noun u3wdb_uni(u3_noun);
u3_noun u3wdb_run(u3_noun); u3_noun u3wdb_run(u3_noun);
# define u3wdb_wyt u3wdi_wyt
u3_noun u3wdi_bif(u3_noun); u3_noun u3wdi_bif(u3_noun);
u3_noun u3wdi_del(u3_noun); u3_noun u3wdi_del(u3_noun);

35
pkg/urbit/jets/d/by_key.c Normal file
View File

@ -0,0 +1,35 @@
/* j/4/by_run.c
**
*/
#include "all.h"
/* internal functions
*/
static u3_noun
_by_key(u3_noun a, u3_noun set)
{
if (u3_nul == a) {
return u3k(set);
} else {
u3_noun n_a, l_a, r_a;
u3_noun p_n_a, q_n_a;
u3x_trel(a, &n_a, &l_a, &r_a);
u3x_cell(n_a, &p_n_a, &q_n_a);
u3_noun with_set = u3qdi_put(set, p_n_a);
u3_noun left_set = _by_key(l_a, with_set);
u3z(with_set);
u3_noun right_set = _by_key(r_a, left_set);
u3z(left_set);
return right_set;
}
}
u3_noun
u3wdb_key(u3_noun cor)
{
u3_noun a;
u3x_mean(cor, u3x_con_sam, &a, 0);
return _by_key(a, 0);
}

View File

@ -1636,7 +1636,9 @@ static c3_c* _141_two__in_ha[] = {
0 0
}; };
static u3j_harm _141_two__by_run_a[] = {{".2", u3wdb_run, c3y}, {}}; static u3j_harm _141_two__by_key_a[] = {{".2", u3wdb_key}, {}};
static u3j_harm _141_two__by_run_a[] = {{".2", u3wdb_run}, {}};
static u3j_harm _141_two__by_wyt_a[] = {{".2", u3wdb_wyt}, {}};
static u3j_harm _141_two__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}}; static u3j_harm _141_two__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}};
static c3_c* _141_two__by_tap_ha[] = { static c3_c* _141_two__by_tap_ha[] = {
@ -1657,9 +1659,11 @@ static u3j_core _141_two__by_d[] =
{ "has", 7, _141_two__by_has_a, 0, _141_two__by_has_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 }, // { "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 }, { "jab", 7, _141_two__by_jab_a, 0, _141_two__by_jab_ha },
{ "key", 7, _141_two__by_key_a },
{ "put", 7, _141_two__by_put_a, 0, _141_two__by_put_ha }, { "put", 7, _141_two__by_put_a, 0, _141_two__by_put_ha },
{ "run", 7, _141_two__by_run_a }, { "run", 7, _141_two__by_run_a },
{ "tap", 7, _141_two__by_tap_a, 0, _141_two__by_tap_ha }, { "tap", 7, _141_two__by_tap_a, 0, _141_two__by_tap_ha },
{ "wyt", 3, _141_two__by_wyt_a },
// { "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha }, // { "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha },
{} {}
}; };