Skip to content

Commit

Permalink
jet +mate arm (#512)
Browse files Browse the repository at this point in the history
These changes introduce a jet for the [`+mate`
arm](https://developers.urbit.org/reference/hoon/stdlib/2a#mate), and
were tested with the following commands:

```
> (mate ~ ~)
~
> (mate ~ `1)
[~ u=1]
> (mate `2 ~)
[~ u=2]
> (mate `3 `3)
[~ u=3]
> (mate `4 `5)
(error)
took ms/2.118
> ~>  %bout  (roll (gulf 1 1.000) |=([n=@ a=(unit @)] (mate (mate `n ~) (mate ~ `n))))
[~ 1.000]
> =hoon-mate |*([a=(unit) b=(unit)] ?~(b a ?~(a b ?.(=(u.a u.b) ~>(%mean.'mate' !!) a))))
took ms/4.603
> ~>  %bout  (roll (gulf 1 1.000) |=([n=@ a=(unit @)] (hoon-mate (hoon-mate `n ~) (hoon-mate ~ `n))))
[~ 1.000]
```

The `+mate` error text (`bail: fail` followed by stack trace) looks
different from the `+need` error text (`dojo: hoon expression failed`)
despite using the same jet error routine (i.e. `u3m_bail(c3__fail)`).
Feedback on this would be appreciated!
  • Loading branch information
pkova authored Nov 15, 2023
2 parents 09df69a + 0335f04 commit 58361b5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/noun/jets/b/mate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"


u3_noun
u3qb_mate(u3_noun a,
u3_noun b)
{
if ( u3_nul == b ) {
return u3k(a);
} else if ( u3_nul == a ) {
return u3k(b);
} else if ( c3y == u3r_sing(u3t(a), u3t(b)) ) {
return u3k(a);
} else {
return u3m_error("mate");
}
}
u3_noun
u3wb_mate(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0);
return u3qb_mate(a, b);
}

2 changes: 2 additions & 0 deletions pkg/noun/jets/q.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
u3_noun u3qb_lien(u3_noun, u3_noun);
u3_noun u3qb_murn(u3_noun, u3_noun);
u3_noun u3qb_need(u3_noun);
u3_noun u3qb_mate(u3_noun, u3_noun);
u3_noun u3qb_reap(u3_atom, u3_noun);
u3_noun u3qb_reel(u3_noun, u3_noun);
u3_noun u3qb_roll(u3_noun, u3_noun);
Expand Down Expand Up @@ -254,3 +255,4 @@
void u3qf_test(const c3_c*, u3_noun);

#endif /* ifndef U3_JETS_Q_H */

4 changes: 4 additions & 0 deletions pkg/noun/jets/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ static u3j_core _139_two__in_d[] =
{}
};

static u3j_harm _139_two_mate_a[] = {{".2", u3wb_mate, c3y}, {}};

static u3j_core _139_two_d[] =
{ { "tri", 3, 0, _139_tri_d, no_hashes, _140_tri_ho },

Expand All @@ -2286,6 +2288,7 @@ static u3j_core _139_two_d[] =
{ "lien", 7, _140_two_lien_a, 0, no_hashes },
{ "murn", 7, _140_two_murn_a, 0, no_hashes },
{ "need", 7, _140_two_need_a, 0, no_hashes },
{ "mate", 7, _139_two_mate_a, 0, no_hashes },
{ "reap", 7, _140_two_reap_a, 0, no_hashes },
{ "reel", 7, _140_two_reel_a, 0, no_hashes },
{ "roll", 7, _140_two_roll_a, 0, no_hashes },
Expand Down Expand Up @@ -2448,3 +2451,4 @@ u3j_Dash = {
0,
0
};

2 changes: 2 additions & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
u3_noun u3wb_lien(u3_noun);
u3_noun u3wb_murn(u3_noun);
u3_noun u3wb_need(u3_noun);
u3_noun u3wb_mate(u3_noun);
u3_noun u3wb_reap(u3_noun);
u3_noun u3wb_reel(u3_noun);
u3_noun u3wb_roll(u3_noun);
Expand Down Expand Up @@ -332,3 +333,4 @@
u3_noun u3wfu_rest(u3_noun);

#endif /* ifndef U3_JETS_W_H */

0 comments on commit 58361b5

Please sign in to comment.