Created
April 13, 2017 22:26
-
-
Save missingfaktor/3d0b2b358dcf35d41ab3c49d21d79175 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ! Our fancy decomposer | |
| : decompose-word ( fog -- f g ) def>> dup length 2/ cut ; | |
| ! Let's define a couple of functions, and a composition thereof to play with. | |
| : inc ( n -- n+1 ) 1 + ; | |
| : square ( n -- n^2 ) dup * ; | |
| : inc-and-square ( n -- (n+1)^2 ) inc square ; | |
| ! Put some number on stack. | |
| 11 | |
| ! Put our "composed" word on stack. | |
| \ inc-and-square | |
| ! Let's decompose it | |
| decompose-word | |
| ! Observe the stack. We now have two different quotation objects there. | |
| ! Let's "invoke both". | |
| [ call ] bi@ | |
| ! We get the result we expected! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment