summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/jets/b/find.c
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
committerpolwex <polwex@sortug.com>2025-10-05 21:56:51 +0700
commitfcedfddf00b3f994e4f4e40332ac7fc192c63244 (patch)
tree51d38e62c7bdfcc5f9a5e9435fe820c93cfc9a3d /vere/pkg/noun/jets/b/find.c
claude is gud
Diffstat (limited to 'vere/pkg/noun/jets/b/find.c')
-rw-r--r--vere/pkg/noun/jets/b/find.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/vere/pkg/noun/jets/b/find.c b/vere/pkg/noun/jets/b/find.c
new file mode 100644
index 0000000..c0295d2
--- /dev/null
+++ b/vere/pkg/noun/jets/b/find.c
@@ -0,0 +1,50 @@
+/// @file
+
+#include "jets/q.h"
+#include "jets/w.h"
+
+#include "noun.h"
+
+STATIC_ASSERT( (UINT32_MAX > u3a_cells),
+ "list index precision" );
+
+u3_noun
+u3qb_find(u3_noun nedl, u3_noun hstk)
+{
+ if ( u3_nul != nedl ) {
+ c3_w i_w = 0;
+
+ while ( u3_nul != hstk ) {
+ u3_noun i_h, t_h = hstk;
+ u3_noun i_n, t_n = nedl;
+ u3x_cell(t_h, &i_h, &t_h);
+ u3x_cell(t_n, &i_n, &t_n);
+
+ while ( c3y == u3r_sing(i_n, i_h) ) {
+ if ( u3_nul == t_n ) {
+ return u3nc(u3_nul, u3i_word(i_w));
+ }
+ else if ( u3_nul == t_h ) {
+ break;
+ }
+ else {
+ u3x_cell(t_h, &i_h, &t_h);
+ u3x_cell(t_n, &i_n, &t_n);
+ }
+ }
+
+ hstk = u3t(hstk);
+ i_w++;
+ }
+ }
+
+ return u3_nul;
+}
+
+u3_noun
+u3wb_find(u3_noun cor)
+{
+ u3_noun a, b;
+ u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0);
+ return u3qb_find(a, b);
+}