retroforth/package/dict-words-listing.forth
crc c0cd63c34f add d:words-missing-details
FossilOrigin-Name: ee2b08e111e4ae15d3a0738022e1fdfa9b84067cd7019f273cc0337275d91e05
2024-09-12 18:54:02 +00:00

46 lines
1.5 KiB
Forth

# Listing Words in the Dictionary
The basic word listing is provided by `d:words`.
~~~
:d:words (:-) [ d:name s:put sp ] d:for-each ;
~~~
This isn't very useful though: a raw list of names is difficult
to read through, and may be intimidating to users. Kiyoshi Yoneda
has implemented some variations that are much more useful.
The first of these is is a variant of `d:words` which displays
words containing a specific substring. It's useful to see words
in a specific namespace, e.g., by doing `'s: d:words-with`, or
words that likely display something: `':put d:words-with`.
~~~
:d:words-with (:s-)
here s:copy
[ d:name dup here
(put-match s:contains/string? [ s:put sp ] [ drop ] choose )
] d:for-each ;
~~~
This does have a drawback if you want words in a namespace as
it does not care where in the name the substring is found. To
deal with this, `d:words-beginning-with` is provided.
~~~
{{
:display-if-left (s-)
dup here s:begins-with? [ s:put sp ] [ drop ] choose ;
---reveal---
:d:words-beginning-with (:s-)
here s:copy [ d:name display-if-left ] d:for-each ;
}}
~~~
~~~
:d:words-missing-details (:-)
'D.Stack: s:put nl [ dup d:stack fetch n:zero? [ d:name s:put sp ] &drop choose ] d:for-each nl
'A.Stack: s:put nl [ dup d:astack fetch n:zero? [ d:name s:put sp ] &drop choose ] d:for-each nl
'F.Stack: s:put nl [ dup d:fstack fetch n:zero? [ d:name s:put sp ] &drop choose ] d:for-each nl
'Desc: s:put nl [ dup d:descr fetch n:zero? [ d:name s:put sp ] &drop choose ] d:for-each nl ;
~~~