Skip to content

Instantly share code, notes, and snippets.

@cmtptr
Last active December 10, 2020 21:41
Show Gist options
  • Save cmtptr/780a826a7ea837c0f58d453c22e7b5c6 to your computer and use it in GitHub Desktop.
Save cmtptr/780a826a7ea837c0f58d453c22e7b5c6 to your computer and use it in GitHub Desktop.
program foo
123 constant qwe
variable x variable y
: part-one blah qwe something x ! ;
: part-two blah blah something-else y !;
: part-three blah blah x @ y @ * or whatever ;
main: part-one part-two part-three ;
end-program
program bar
variable x ( different from foo's x )
: part-one x @ dup 1+ x ! ; ( different from foo's part-one )
( when bar recurses, the inner bar gets its own instance of x, like
stack frames in c )
main: part-one 1 and if bar then ;
end-program
( call foo and bar as words themselves, and they execute with their own private
contexts per each invokation )
: baz foo bar ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment