urbit
urbit copied to clipboard
hoon: jib and jub wip
Adds +jib
(like +jab
, but slam the gate with its bunt if the key is missing) and +jub
(like +jab
, but slam the gate with ~
if the key is missing and [~ q.n.a]
if present) to the stdlib
NOT YET TESTED
https://github.com/xiphiness/urbit/tree/x/jub https://github.com/xiphiness/vere/tree/x/jub
In December I worked on jub (I had it named the same), with the modification that also, it returns a unit, deleting if the kv pair is present and the gate returns a ~. I had thought there was an issue with wet gates and the function, but turns out it was with the jet I wrote. I lost a lot of the code, but for core school homework I rewrote both the jet and the hoon code.
if @xiphiness has jets for this I'd like to propose that it be merged once those are ready.
My jub is a superset of what your jub provides.
I'm not sure about my reference hygiene for one, secondly, for those who know treaps better, in the case of the recursive calls, are my use of puts needed in the case that the recursive call returns an empty map? or is there something cleverer I can do?
I can accommodate your jib too. I just wrote the jet for it, but thinking about it, I don't think it's going to work with the hoon you wrote. Jab is designed to crash if the value doesn't exist, and moreover, it will I believe crash at the building-of-the-gate step if the map is empty. The value of the sample of the gate passed being a _?>(?=(^ a) q.n.a)
rather than _?>(?=(^ a) q.n.a)
means I think that it implicitly becomes a wet version of a _?>(?=(^ a) |:(q.n.a q.n.a)), i.e. the sample is constructed by asserting a non-empty map and grabbing the root node. Turning the function into a $-(* *)
should probably work, as run:by does, but the question then becomes whether or not we add a deletion semantics as with my jub by returning a unit.
But in theory my jub handles all use cases, and the pattern you'd use with your jib can be slightly more verbosely expressed by wrapping the gate fun
you would put into your jib into a |=((unit val) ?~(+<
$:fun (fun u)))
.
https://github.com/urbit/urbit/pull/6782