This reverts commit 8e1e40d75b3ab15c194b6bf9570f3edc46e2de58. This reverts commit f073c490f9fd7c5abc033af4857df92229877de7. This reverts commit f187d2d7e01a54823f3e979af9bbd148b398e7e9. This reverts commit bc272862a73cfce1b118586ca39d3a377d841f1b. This reverts commit 30a397513f8890a3406dc7ab91c6e067e3bbfbbb. This reverts commit 4fc6856fb50d88c20a0f533392ca606641c5f38f. Conflicts: urb/urbit.pill urb/zod/base/lib/drum.hoon
1.6 KiB
barhep, |-
, %brhp
Kicked trap
|-
is a synthetic rune that produces a dry %gold
trap and
kicks it. You can think of a trap like a 'trap door', since |-
is
a door
with only one arm $
, the empty name.
|-
is different from |.
in that it is kicked by default. |-
is
similar to creating and calling an anonymous function and is quite
commonly used for loops or recursion.
See also
Produces
Twig: [%brhp p=twig]
Sample
p
is a twig
Tall form
|- p
Wide form
|-(p)
Irregular form
None
Examples
/~zod/try=> |-(42)
42
In contrast to our |.
example, |-
is kicked by default, so its
internals are produced immediately.
/~zod/try=> =+ a=`*`~[41 42]
|-
?~ a
~
[-.a %m $(a +.a)]
[41 %m [42 %m ~]]
In this case we use |-
for one of its most common applications, a
loop. Here we walk across a
by calling $
with a
replaced by +.a
,
producing a nested tuple.
++ dec :: decrement
~/ %dec
|= a=@
~| %decrement-underflow
?< =(0 a)
=+ b=0
|- ^- @
?: =(a +(b))
b
$(b +(b))
In ++dec
, found in hoon.hoon
, |-
creates a trap that contains the
test and looping semantics. Essentially, we count up to a-1
by
incrementing b
. Using |-
inside an existing core as we do here is
its most common use.