Skip to content

Instantly share code, notes, and snippets.

@kozross
Last active December 17, 2016 03:50
Show Gist options
  • Save kozross/e3491a79c105c82557a47d3965197e5e to your computer and use it in GitHub Desktop.
Save kozross/e3491a79c105c82557a47d3965197e5e to your computer and use it in GitHub Desktop.
\ This example is straight from Starting Forth.
HERE 5 CELLS ALLOT BASE !
: limit ( index -- addr ) CELLS [ BASE @ ] LITERAL + ;
DECIMAL
\ Is there a way to avoid the first line (i.e. dumping the address into a 'scratch variable')?
\ My initial thinking was something like:
: limit ( index -- addr ) CELLS [ HERE 5 CELLS ALLOT ] LITERAL + ;
\ But this definitely does not produce what I want, as evidenced by this result:
SEE limit
\ prints : limit
\ cells <-7378697629483820647> <-7378697629483820647> <-7378697629483820647> <-7378697629483820647> <-3740130035007645287> 140405810139648 + ; ok
\ I'm not sure why I'm getting this behaviour. Could someone please explain what I'm missing?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment