c2f700172b
FossilOrigin-Name: abca4688608aaba862170b22b0c031c00551e711ca9d98068f3590071c4a96c7
40 lines
1.1 KiB
Forth
40 lines
1.1 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`.
|
|
|
|
~~~
|
|
{{
|
|
:display-if-matched (s-)
|
|
here over s:contains-string? [ s:put sp ] [ drop ] choose ;
|
|
---reveal---
|
|
:d:words-with (s-)
|
|
here s:copy [ d:name display-if-matched ] 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 ;
|
|
}}
|
|
~~~
|