Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created April 13, 2017 22:26
Show Gist options
  • Select an option

  • Save missingfaktor/3d0b2b358dcf35d41ab3c49d21d79175 to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/3d0b2b358dcf35d41ab3c49d21d79175 to your computer and use it in GitHub Desktop.
! 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