From 8e0c4dd16b049e84cd08c48b11f3e75a3f4a42b5 Mon Sep 17 00:00:00 2001 From: crc Date: Wed, 6 Feb 2019 12:45:02 +0000 Subject: [PATCH] add two new examples from Kiyoshi FossilOrigin-Name: 4f930733947c1331f846262d820152b2a6276dc9cd7cf1fa307129dbff71157c --- RELEASE_NOTES.md | 3 ++ example/EvaluateString.forth | 15 ++++++++ example/Forget.forth | 67 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 example/EvaluateString.forth create mode 100644 example/Forget.forth diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 5e47829..8050218 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -97,9 +97,12 @@ June 2019. ## Examples +- add Abort.forth - add Buffer.forth - add CaptureOutput.forth - add DisplayNames.forth +- add EvaluateString.forth +- add Forget.forth - add HTML.forth - add KeyValueStore.forth - add Marker.forth diff --git a/example/EvaluateString.forth b/example/EvaluateString.forth new file mode 100644 index 0000000..03ad9ea --- /dev/null +++ b/example/EvaluateString.forth @@ -0,0 +1,15 @@ +## s:(evaluate) + +Show string being evaluated + +~~~ +:s:() (s-) nl '(_ s:prepend '_) s:append s:put nl ; +:s:(evaluate) (s-) dup s:() s:evaluate nl ; +~~~ + +``` +:s:testing (s--) 'Testing_ s:prepend s:put nl ; +'s:(evaluate) s:testing +'#2_#3_#136_dump-stack s:(evaluate) +'reset_dump-stack s:(evaluate) +``` diff --git a/example/Forget.forth b/example/Forget.forth new file mode 100644 index 0000000..68233bf --- /dev/null +++ b/example/Forget.forth @@ -0,0 +1,67 @@ +# Forget + +This is an alternative to `mark`. + +As a byproduct you get `hide` which hides a word from later +dictionary search. + +~~~ +:d:exists? d:lookup n:zero? ; +'abort d:exists? [ 'example/Abort.forth include ] if +'s:(evaluate) d:exists? [ 'example/EvaluateString.forth include ] if +~~~ + +## EOC (end-of-code) + +~~~ +:d:size (-) #0 [ d:name drop #1 + ] d:for-each ; +:d:words.last (n-) + &Dictionary swap [ fetch dup d:name s:put sp d:link ] times drop ; +:EOC (-) 'EOC_(end-of-code) s:shout + d:size '%n_words_defined s:format s:put nl + #4 [ '%n_last_defined_words: s:format s:put sp ] sip d:words.last listen ; +~~~ + +## d:hide + +~~~ +{{ + 'This 'Newer [ var ] bi@ + :names-match? (a-f) d:name here s:eq? ; + :word-exists?continue (s-s) [ dup d:lookup ] assert ; + :d:newer-older (s-aa)_newer_older word-exists?continue + here s:copy d:last #0 !Newer [ dup names-match? + [ @Newer TRUE ] [ dup !Newer d:link fetch FALSE ] choose + ] until (this_newer) swap d:link fetch (older) ; + :exist?continue (aa-aa) [ dup-pair [ n:-zero? ] bi@ and ] assert ; +---reveal--- + :d:newer (s-a) d:newer-older drop ; + :d:hide (s-) d:newer-older exist?continue swap d:link store ; +}} +~~~ + + +``` +:a ; :b ; :c ; +'b d:hide +'#5_d:words.last s:(evaluate) +``` + +# Forget + +~~~ +:d:forget.a (a-) dup n:-zero? [ dup !Heap d:link fetch !Dictionary ] + [ drop 'tried_to_d:forget_a_word_that_doesn't_exist. s:shout ] choose ; +:d:forget (s-) d:lookup d:forget.a ; +:f:reset (-|float:?-) f:depth [ f:drop ] times ; +:reset.nf (?-|float:?-) reset f:reset ; +:d:wipe (-) reset.nf '---wipe--- d:newer d:forget.a ; +~~~ + +``` +:---wipe--- ; +:a ; :b ; :c ; nl +'#5_d:words.last s:(evaluate) +d:wipe nl +'#5_d:words.last s:(evaluate) nl +```