From cd9f9de76cb8ea21ab214e60053433ed00f4e2ae Mon Sep 17 00:00:00 2001 From: crc Date: Fri, 23 Aug 2019 20:32:38 +0000 Subject: [PATCH] add example of generating an array of defined namespaces FossilOrigin-Name: d235718eeec6ad108f7b11f910b73eeeccab8dae1a0ef9f4c9e3a472b98f9e9b --- example/namespaces.retro | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 example/namespaces.retro diff --git a/example/namespaces.retro b/example/namespaces.retro new file mode 100644 index 0000000..7017b26 --- /dev/null +++ b/example/namespaces.retro @@ -0,0 +1,33 @@ +This is a little set of words to create an array with all of the +currently defined namespaces in a RETRO image. + +Three words will be exposed. + + Namespace Array, holds the namespace strings + namespaces:identify Rebuild the array + namespaces:put Display the namespaces + +~~~ +'Namespaces d:create #513 allot + +{{ + :has-namespace? dup $: s:contains-char? ; + :get-namespace $: s:split nip ; + :known? dup &Namespaces a:contains-string? ; + :add s:keep buffer:add &Namespaces v:inc ; + :process get-namespace known? &drop &add choose ; +---reveal--- + :namespaces:identify + [ &Namespaces buffer:set #0 buffer:add + [ d:name has-namespace? &process &drop choose ] d:for-each + ] buffer:preserve ; + :namespaces:put &Namespaces [ s:put sp ] a:for-each ; +}} +~~~ + +A quick test: + +``` +namespaces:identify +namespaces:put nl +```