mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Remove unnecessary swap, give array helper word a better name.
This commit is contained in:
parent
a49ab049a5
commit
6b5c06d45a
@ -161,13 +161,13 @@ create mynumbers 64 , 9001 , 1337 , \ ok (the last `,` is important!)
|
||||
0 cells mynumbers + ? \ 64 ok
|
||||
1 cells mynumbers + ? \ 9001 ok
|
||||
|
||||
\ We can simplify it by making a helper word for manipulating arrays:
|
||||
: arr ( n n -- n ) cells swap + ;
|
||||
mynumbers 2 arr ? \ 1337 ok
|
||||
\ We can simplify it a little by making a helper word for manipulating arrays:
|
||||
: of-arr ( n n -- n ) cells + ; \ ok
|
||||
mynumbers 2 of-arr ? \ 1337 ok
|
||||
|
||||
\ Which we can use for writing too:
|
||||
20 mynumbers 1 arr ! \ ok
|
||||
mynumbers 1 arr ? \ 20 ok
|
||||
20 mynumbers 1 of-arr ! \ ok
|
||||
mynumbers 1 of-arr ? \ 20 ok
|
||||
|
||||
\ ------------------------------ The Return Stack ------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user