14Produces the indices of all occurrences of `nedl` in `hstk` as a `list` of
32 |= [nedl=(list) hstk=(list)]
38 ?: |(?=($~ n) ?=($~ h))
42 ^$(i +(i), hstk +.hstk, fnd [i fnd])
44 ^$(i +(i), hstk +.hstk)
50 > (fand ~[3] ~[1 2 3])
53 > (fand ~[4] ~[1 2 3])
56 > (fand ~['a'] "cbabab")
59 > (fand "ba" "cbabab")
69Produces the index of the first occurrence of `nedl` in `hstk` as the `unit`
87 |= [nedl=(list) hstk=(list)]
92 ?: |(?=($~ n) ?=($~ h))
98 ^$(i +(i), hstk +.hstk)
104 > (find [3]~ ~[1 2 3])
107 > (find [4]~ ~[1 2 3])
110 > (find ['c']~ "cbabab")
113 > (find "ab" "cbabab")
116 > (find "bab" "cbabab")
125Produces the `list` `a` in reverse order.
166Produces a `list` composed of each consecutive integer starting from `a` and
167ending with `b`. `a` and `b` are themselves included.
185 ?:(=(a +(b)) ~ [a $(a +(a))])
194 > `(list @t)`(gulf 99 106)
203Produces a `list` whose type is a fork of all the contained types in the
204list `a`. Used when you want to make all the types of the elements of a list the
221 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
230 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
233 ~[1 97 2 98 [~ u=10]]
235 > =a (limo [1 2 3 ~])
237 [i=1 t=[i=2 t=[i=3 t=~]]]
249Produces the length of any `list` `a` as an atom.
275 > (lent [1 2 3 4 ~]))
278 > (lent [1 'a' 2 'b' (some 10) ~])
288Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `list` `a`.
305 |* [a=(list) b=$-(* ?)]
315 > =a |=(a=@ (lte a 1))
316 > (levy `(list @)`[0 1 2 1 ~] a)
319 > =a |=(a=@ (lte a 3))
320 > (levy `(list @)`[0 1 2 1 ~] a)
331Computes the Boolean logical "or" on the results of applying `gate` `b` to
332every element of `++list` `a`.
345 |* [a=(list) b=$-(* ?)]
355 > =a |=(a=@ (gte a 1))
356 > (lien `(list @)`[0 1 2 1 ~] a)
359 > =a |=(a=@ (gte a 3))
360 > (lien `(list @)`[0 1 2 1 ~]) a)
370Turns a null-terminated tuple into a `list`.
374`a` is a null-terminated tuple.
386 |% +- $ ?~(a ~ ?:(_? i=-.a t=$ $(a +.a)))
395 [i=1 t=[i=2 t=[i=3 t=~]]]
404Passes each member of `list` `a` to gate `b`, which must produce a
405`unit`. Produces a new list with all the results that do not produce
412`b` is a gate that produces a unit.
421 ++ murn :: maybe transform
423 |* [a=(list) b=$-(* (unit))]
435 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
436 > (murn `(list @)`[0 1 2 3 ~] a)
446Removes elements from list `c` beginning at inclusive index `a`, removing `b`
462 |* [[a=@ b=@] c=(list)]
463 (weld (scag a c) (slag (add a b) c))
469 > (oust [4 5] "good day, urbit!")
472 > (oust [2 2] `(list @)`[1 2 3 4 ~])
482Replicate: produces a `list` containing `a` copies of `b`.
509 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
512 ~[~s1 ~s1 ~s1 ~s1 ~s1]
514 > `@dr`(roll (reap 5 ~s1) add)
524Right fold: moves right to left across a `list` `a`, recursively slamming
525a binary gate `b` with an element from `a` and an accumulator, producing
526the final value of the accumulator.
528(To "slam" means to call a gate and give it a sample/samples. In this instance,
529`a` is the list of samples that are given to the gate b.)
539The accumulator, which is a noun.
546 |* [a=(list) b=_|=([* *] +<+)]
556 > =sum =|([p=@ q=@] |.((add p q)))
557 > (reel (limo [1 2 3 4 5 ~]) sum)
560 > =a =|([p=@ q=@] |.((sub p q)))
561 > (reel (limo [6 3 1 ~]) a)
564 > (reel (limo [3 6 1 ~]) a)
575Left fold: moves left to right across a list `a`, recursively slamming a
576binary gate `b` with an element from the `list` and an accumulator,
577producing the final value of the accumulator.
579(To "slam" means to call a gate and give it a sample/samples. In this instance,
580`a` is the list of samples that are given to the gate b.)
590The accumulator, which is a noun.
597 |* [a=(list) b=_|=([* *] +<+)]
601 $(a t.a, b b(+<+ (b i.a +<+.b)))
607 > =sum =|([p=@ q=@] |.((add p q)))
608 > (roll (limo [1 2 3 4 5 ~]) sum)
611 > =a =|([p=@ q=@] |.((sub p q)))
612 > (roll (limo [6 3 1 ~]) a)
616 > (roll (limo [1 3 6 ~]) a)
626Accepts an atom `a` and `list` `b`, producing the first `a` elements of
627the front of the list.
637A list of the same type as `b`.
646 ?: |(?=(~ b) =(0 a)) ~
647 [i.b $(b t.b, a (dec a))]
653 > (scag 2 `(list @)`[1 2 3 4 ~])
656 > (scag 10 `(list @)`[1 2 3 4 ~])
666Separates a `list` `a` into two lists - Those elements of `a` who produce
667true when slammed to gate `b` and those who produce `%.n`.
669(To "slam" means to call a gate and give it a sample/samples. In this instance,
670`a` is the list of samples that are given to the gate `b`.)
676`b` is a gate that accepts one argument and produces a flag.
687 |* [a=(list) b=$-(* ?)]
691 ?:((b i.a) [[i.a p.c] q.c] [p.c [i.a q.c]])
698 > =a |=(a=@ (gth a 1))
699 > (skid `(list @)`[0 1 2 3 ~]) a)
700 (skid `(list @)`[0 1 2 3 ~]) a)
709Cycles through the members of a list `a`, passing them to a gate `b` and
710producing a list of all of the members that produce `%.y`. Inverse of
717`b` is a gate that accepts one argument and produces a boolean.
728 |* [a=(list) b=$-(* ?)]
732 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
738 > =a |=(a=@ (gth a 1))
739 > (skim `(list @)`[0 1 2 3 ~] a)
748Cycles through the members of `list` `a`, passing them to a gate `b`.
749Produces a list of all of the members that produce `%.n`. Inverse of
756`b` is a gate that accepts one argument and produces a flag.
760A list of the same type as `a`.
767 |* [a=(list) b=$-(* ?)]
771 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
777 > =a |=(a=@ (gth a 1))
778 > (skip `(l)`[0 1 2 3 ~]) a)
788Accepts an atom `a` and list `b`, producing the remaining elements from
797A list of the same type as `b`.
814 > (slag 2 (limo [1 2 3 4 ~]))
816 > (slag 1 (limo [1 2 3 4 ~]))
817 [i=2 t=[i=3 t=[i=4 t=~]]]
826Accepts an atom `a` and a `++list` `b`, producing the element at the index
827of `a`and failing if the list is null. Lists are 0-indexed.
835Produces an element of `b`, or crashes if no element exists at that index.
855 > (snag 0 `(list @ud)`~[1 2 3 4])
865Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
866produces a flag. `++sort` then produces a list of the elements of `a`,
867sorted according to `b`.
871`b` is a gate that accepts two nouns and produces a boolean.
880 ++ sort !. :: quicksort
882 |* [a=(list) b=$-([* *] ?)]
887 $(a (skim t.a |=(c/_i.a (b c i.a))))
889 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
895 > =a =|([p/@ q/@] |.((gth p q)))
896 > (sort (limo [0 1 2 3 ~]) a)
904Gate to list, with state
906Accepts a `++list` `a`, a gate `b`, and some state `c`. Produces a list with
907the gate applied to each element of the original list. `b` is called with
908a tuple -- the head is an element of `a` and the tail is the state `c`, and
909should produce a tuple of the transformed element and the (potentially
929 |* [a=(list) b=* c=_|=(^ [** +<+])]
930 => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
931 =/ acc=(list _-:(c)) ~
936 $(acc [res acc], a t.a)
942 > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
947 > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
948 |=([n=@ a=@] [`(pair)`[a n] +(a)])
950 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
952 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
953 |=([n=@ rng=_og] (rads:rng 10))
955 ~[5 5 9 4 1 7 9 9 9 6]
960`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
961with entropy (`eny`). The head of the product is the random number, the tail
962is the continuation of the RNG.
969Gate to list, with state
971Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
972derived by *bunting* the tail of the sample of gate `b`, instead of
973being passed in explicitly as in `++spin`. Produces a list with the
974gate applied to each element of the original list. `b` is called with a tuple --
975the head is an element of `a` and the tail is the state `c`, and should
976produce a tuple of the transformed element and the (potentially modified)
994 |* [a=(list) b=_|=(^ [** +<+])]
1001 > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1002 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1003 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1005 > =l (limo ~[7 8 9])
1006 > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
1007 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1008 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1017Similar to `substr` in Javascript: extracts a string infix, beginning at
1018inclusive index `a`, producing `b` number of characters.
1026A list of the same type as `c`.
1032 |* [[a=@ a=@] c=(list)]
1033 (scag +<-> (slag +<-< c))
1039 > (swag [2 5] "roly poly")
1042 > (swag [2 2] (limo [1 2 3 4 ~]))
1052Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
1053to each element of the original list.
1068 |* [a=(list) b=gate]
1071 [i=(b i.a) t=$(a t.a)]
1077 > (turn (limo [104 111 111 110 ~]) @t)
1080 > =a |=(a=@ (add a 4))
1081 > (turn (limo [1 2 3 4 ~]) a)
1087`turn` is Hoon's version of 'map' in Haskell.
1094Concatenate two `++list`s `a` and `b`.
1098`a` and `b` are lists.
1105 |* [a=(list) b=(list)]
1106 => .(a ^.(homo a), b ^.(homo b))
1116 ~[~~u ~~r ~~b ~~i ~~t]
1118 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1128Concatenate two `++list`s `a` and `b` without losing their type information
1157 > (welp "foo" "bar")
1160 > (welp ~[60 61 62] ~[%a %b %c])
1161 [60 61 62 %a %b %c ~]
1163 > ? (welp ~[60 61 62] ~[%a %b %c])
1164 {@ud @ud @ud $a $b $c $~}
1165 [60 61 62 %a %b %c ~]
1167 > (welp [sa+1 so+2 ~] si=3)
1168 [[%sa 1] [%so 2] si=3]
1177Turns a `++list` of lists into a single list by promoting the elements of
1178each sublist into the higher.
1197 (welp +<- $(+< +<+))
1205 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1206 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1208 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1209 ~[1 97 2 98 3 99 4 100]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list