From eb9383a6392eb4286da44b6ce06c5e6e6be70e9d Mon Sep 17 00:00:00 2001 From: crc Date: Thu, 14 Mar 2019 18:01:28 +0000 Subject: [PATCH] add example/CloseParen.forth FossilOrigin-Name: 2e440f95f4058f94bd270dd2f510b87bb73ab813e7bd08e8bd1c453e8b14b3df --- RELEASE_NOTES.md | 1 + example/CloseParen.forth | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 example/CloseParen.forth diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d64c109..24e143c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -152,6 +152,7 @@ June 2019. - add Block-Editor.forth - add Buffer.forth - add CaptureOutput.forth +- add CloseParen.forth - add DisplayNames.forth - add EDA.forth - add EvaluateString.forth diff --git a/example/CloseParen.forth b/example/CloseParen.forth new file mode 100644 index 0000000..8970526 --- /dev/null +++ b/example/CloseParen.forth @@ -0,0 +1,35 @@ +I find `)` useful to punctuate code chunks. + +~~~ +:) ; immediate (code_chunk_punctuation_that_does_nothing +~~~ + +Here is an example: + + :i@ (an-n) array:nth fetch ; + +~~~ +{{ + :I@ (an-n) I array:nth fetch ; + 'Index 'Value [ var ] bi@ + :lt?-or-gt? hook ; + :pre.min (a-an) + (comparison <? <?-or-gt? set-hook ) + (begin_with #-1 !Index n:MAX !Value dup array:length ) ; + :pre.max (a-an) + (comparison >? <?-or-gt? set-hook ) + (begin_with #-1 !Index n:MIN !Value dup array:length ) ; + :min-or-max (a-nn) [ dup I@ dup @Value lt?-or-gt? + [ !Value I !Index ] [ drop ] choose ] times + (a-nn drop @Index @Value ) ; +---reveal--- + :array:min (a-iv) pre.min min-or-max ; + :array:max (a-iv) pre.max min-or-max ; +}} +~~~ + +``` +{ #3 #2 #5 #7 #3 } array:min dump-stack nl reset +{ #3 #2 #5 #7 #3 } array:max dump-stack nl +``` +