From 1e1e5e469d6ffe9677e357f3b8e2a0d4bac6e645 Mon Sep 17 00:00:00 2001 From: crc Date: Mon, 13 May 2019 17:29:20 +0000 Subject: [PATCH] add DO LOOP +LOOP to example/compat.forth FossilOrigin-Name: 1c2c94fff681153c259cddf2ab9d1a60e042d7270ea0190f5965b3d36429d5ce --- example/compat.forth | 6 +++++- example/quad.forth | 15 ++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/example/compat.forth b/example/compat.forth index 5912354..271c3b8 100644 --- a/example/compat.forth +++ b/example/compat.forth @@ -53,6 +53,9 @@ with tradition as well as the minimal requirements of ANS. :AGAIN |again ; immediate :FOR |[ ; immediate :NEXT |] |times ; immediate +:DO |[ |[ |[ ; immediate +:LOOP |] |dip |] |dip |n:inc |dup-pair |gt? |] |while |drop-pair ; immediate +:+LOOP |] |dip |] |dip |swap |push |+ |pop |swap |dup-pair |gt? |] |while |drop-pair ; immediate ~~~ ## I/O @@ -172,7 +175,8 @@ The following words are not supported due to design choices in RETRO. -------- -------- -------- -------- -------- -------- # #> #S ' ( ." ['] : >IN [CHAR] ABORT" CONSTANT - CREATE POSTPONE S" SOURCE VARIABLE WORD + CREATE EXIT POSTPONE S" SOURCE VARIABLE + WORD -------- -------- -------- -------- -------- -------- The following are not supported due to limitations of the VM. diff --git a/example/quad.forth b/example/quad.forth index d71bf71..e623cf4 100644 --- a/example/quad.forth +++ b/example/quad.forth @@ -1,6 +1,10 @@ -The standard RETRO language provides `bi` and `tri` combinators to apply quotes to two or three values in various combinations. Sometimes it may be necessary to do this with four values. +The standard RETRO language provides `bi` and `tri` combinators +to apply quotes to two or three values in various combinations. +Sometimes it may be necessary to do this with four values. -Note that this is *ugly* code. It's functional, but if you can refactor to avoid needing it, it'll likely be better in the long run. +Note that this is *ugly* code. It's functional, but if you can +refactor to avoid needing it, it'll likely be better in the long +run. `quad` applies four quotes to a value. These are equivilent: @@ -19,7 +23,8 @@ Note that this is *ugly* code. It's functional, but if you can refactor to avoid pop pop call ; ~~~ -`quad*` takes eight values (!) and applies each quote to a specific value. E.g., these are equivilent: +`quad*` takes eight values (!) and applies each quote to a +specific value. E.g., these are equivilent: #10 [ #1 + ] call #11 [ #1 - ] call @@ -36,7 +41,8 @@ Note that this is *ugly* code. It's functional, but if you can refactor to avoid pop pop call ; ~~~ -`quad@` takes four values and a quote, and applies the quote to each value in order. These are equivilent: +`quad@` takes four values and a quote, and applies the quote to +each value in order. These are equivilent: #10 [ #1 + ] call #11 [ #1 + ] call @@ -49,4 +55,3 @@ Note that this is *ugly* code. It's functional, but if you can refactor to avoid :quad@ (abcdq-) 'abcde 'abcdeeee reorder quad* ; ~~~ -