summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHorseMD <alightedness@gmail.com>2014-11-14 12:12:30 +0000
committerHorseMD <alightedness@gmail.com>2014-11-14 12:12:30 +0000
commitce1d44b308150c88ee61c819ed4b2242af4fcf14 (patch)
tree32342dbfd8aff87ce2abb652ec847eb18fd18a80
parent6b5c06d45a8ee067fcb62bb6e02b6dd95c634292 (diff)
Use our word 'square' in the loop example word 'squares'.
-rw-r--r--forth.html.markdown5
1 files changed, 3 insertions, 2 deletions
diff --git a/forth.html.markdown b/forth.html.markdown
index 0521a3ab..25a9f3b8 100644
--- a/forth.html.markdown
+++ b/forth.html.markdown
@@ -70,9 +70,10 @@ Forth, but most of what is written here should work elsewhere.
\ The `:` word sets Forth into compile mode until it sees the `;` word.
: square ( n -- n ) dup * ; \ ok
+5 square . \ 25 ok
\ We can view what a word does too:
-see square \ dup * ; ok
+see square \ : square dup * ; ok
\ -------------------------------- Conditionals --------------------------------
@@ -109,7 +110,7 @@ one-to-12 \ 0 1 2 3 4 5 6 7 8 9 10 11 12 ok
\ `?do` works similarly, except it will skip the loop if the end and start
\ numbers are equal.
-: squares ( n -- ) 0 ?do i dup * . loop ; \ ok
+: squares ( n -- ) 0 ?do i square . loop ; \ ok
10 squares \ 0 1 4 9 16 25 36 49 64 81 ok
\ Change the "step" with `+loop`: