retroforth/example/namespaces.retro
crc 06ee9705a8 image: rename some words
s:contains-char?  to  s:contains/char?
s:contains-string? to s:contains/string?
a:contains-string? to a:contains/string?

old names are now deprecated and will be removed after 2021.7.

FossilOrigin-Name: 5a19d7aac514c5ba87963c5f0645f3daa8a8e3dc04546c0627fa046479ecd8dd
2021-06-04 13:54:21 +00:00

33 lines
862 B
Forth

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
```