Last active
September 23, 2017 03:05
-
-
Save belisarius222/d2b650ed9b821b613aa1cc2711bbef6e to your computer and use it in GitHub Desktop.
some examples of compiling hoon to nock
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
:: | |
:::: it's a trap! | |
:: | |
!= | |
=/ a 3 | |
|. | |
?: =(a 5) | |
a | |
$(a +(a)) | |
:: | |
[8 | |
[1 3] :: =/ a 3 | |
[1 | |
[6 :: ?: | |
[5 :: = | |
[0 6] :: a | |
[1 5] :: 5 | |
] | |
[0 6] :: a | |
[9 :: |. | |
2 :: $ | |
[ :: <core> | |
[0 2] :: $ <battery> | |
[ :: <payload> | |
[4 0 6] :: +(a) <sample> | |
[0 7] :: +> <context> | |
] :: </payload> | |
] :: </core> | |
] | |
] | |
[0 1] :: previous subject | |
] | |
] | |
:: | |
:::: a simple gate | |
:: | |
!= | |
=/ g |=(a/@ +(a)) :: define a gate: g | |
(g) :: call with no args | |
:: | |
[8 :: =/ g | |
[8 :: |= | |
[1 0] :: a/@ | |
[ | |
[1 4 0 6] :: +(a) | |
[0 1] :: previous subject | |
[ | |
] | |
[7 :: compose formulas | |
[0 2] :: set g as the subject | |
[9 :: evaluate an arm in a core | |
2 :: at axis 2 (the only arm) | |
[0 1] :: with current subject as the core | |
] | |
] | |
] | |
:: | |
:::: now let's call the gate with an actual sample | |
:: | |
!= | |
=/ g |=(a/@ +(a)) | |
(g 77) | |
:: | |
[8 :: =/ g | |
[8 :: |= | |
[1 0] :: a/@ | |
[ | |
[1 4 0 6] :: +(a) | |
[0 1] :: previous subject | |
] | |
] | |
[8 | |
[0 2] :: set g as the subject | |
[9 :: evaluate an arm in a core | |
2 :: at axis 2 (the only arm) | |
[ :: create a core using pair of formulas | |
[0 4] :: grab head of head | |
[7 :: compose formulas | |
[0 3] :: grab tail | |
[1 77] :: replace default sample with arg | |
] | |
] | |
] | |
] | |
[0 11] :: | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment