Created
June 14, 2016 04:40
-
-
Save joemfb/7a7d5625c9704cbb910343efe01fda68 to your computer and use it in GitHub Desktop.
produces the cartesian product of two sets-of-strings in Hoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- %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