Skip to content

Instantly share code, notes, and snippets.

@joemfb
Created June 14, 2016 04:40
Show Gist options
  • Save joemfb/7a7d5625c9704cbb910343efe01fda68 to your computer and use it in GitHub Desktop.
Save joemfb/7a7d5625c9704cbb910343efe01fda68 to your computer and use it in GitHub Desktop.
produces the cartesian product of two sets-of-strings in Hoon
:- %say |= * :- %noun
=< (cartesian-product (sy ['a' 'b' 'c' ~]) (sy ['x' 'y' 'z' ~]))
::
|% ++ cartesian-product
|= {a/(set @t) b/(set @t)}
=+ r=*(set {@t @t})
|- ?~ a r
=+ b=b :: shadow b for inner loop walkthru
|- ?~ b
=+ ^= r
^$(a l.a, r r)
^$(a r.a, r r)
=+ ^= r
(~(put in r) [n.a n.b])
=+ ^= r
$(b l.b, r r)
$(b r.b, r r)
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment