I am a Forth novice writing an application with many fixed text strings of widely differing lengths, indexed by two dimensions (with several additional attributes, like title and date.) I am currently using gForth.
I plan to create about 600 words like:
Group1Subgroup7Title ( -- caddr len ) S" A Subgroup Title" ;
But my question is: how can I programmatically execute a word from a string I've generated within another word? It seems like I need to put the word in the input buffer and call parse-word, but I haven't discovered how to do that. For example:
: PrintTitle ( group sub -- )
make-subgroup-title \ consumes group & sub, returns caddr and len or cstring somehow-invoke-the-word-that-text-represents \ returns caddr len
type ;
I can write make-subgroup-title, but do not understand how to write somehow-invoke-the-word-that-text-represents.
Thanks for your time!
Van Kichline schrieb am Montag, 27. März 2023 um 02:08:07 UTC+2:
I am a Forth novice writing an application with many fixed text strings of widely differing lengths, indexed by two dimensions (with several additional attributes, like title and date.) I am currently using gForth.Try something along PARSE-NAME EVALUATE
I plan to create about 600 words like:
Group1Subgroup7Title ( -- caddr len ) S" A Subgroup Title" ;
But my question is: how can I programmatically execute a word from a string I've generated within another word? It seems like I need to put the word in the input buffer and call parse-word, but I haven't discovered how to do that. For example:
: PrintTitle ( group sub -- )
make-subgroup-title \ consumes group & sub, returns caddr and len or cstring
somehow-invoke-the-word-that-text-represents \ returns caddr len
type ;
I can write make-subgroup-title, but do not understand how to write somehow-invoke-the-word-that-text-represents.
Thanks for your time!
minforth schrieb am Montag, 27. März 2023 um 07:44:53 UTC+2:
Van Kichline schrieb am Montag, 27. März 2023 um 02:08:07 UTC+2:Another helper word to separate names within non-empty(!) strings:
I am a Forth novice writing an application with many fixed text strings of widely differing lengths, indexed by two dimensions (with several additional attributes, like title and date.) I am currently using gForth.Try something along PARSE-NAME EVALUATE
I plan to create about 600 words like:
Group1Subgroup7Title ( -- caddr len ) S" A Subgroup Title" ;
But my question is: how can I programmatically execute a word from a string I've generated within another word? It seems like I need to put the word in the input buffer and call parse-word, but I haven't discovered how to do that. For example:
: PrintTitle ( group sub -- )
make-subgroup-title \ consumes group & sub, returns caddr and len or cstring
somehow-invoke-the-word-that-text-represents \ returns caddr len
type ;
I can write make-subgroup-title, but do not understand how to write somehow-invoke-the-word-that-text-represents.
Thanks for your time!
: PARSE-STRING ( a u -- a' u' ap up )
BEGIN over c@ bl = WHILE 1 /string REPEAT
over >r
BEGIN over c@ bl <> WHILE 1 /string REPEAT
over r@ - r> swap ;
\ test
s" fair may 2023 "
parse-string cr type
parse-string cr type
parse-string cr type
I am a Forth novice writing an application with many fixed text strings of widely differing lengths, indexed by two dimensions (with several additional attributes, like title and date.) I am currently using gForth.
I plan to create about 600 words like:
Group1Subgroup7Title ( -- caddr len ) S" A Subgroup Title" ;
But my question is: how can I programmatically execute a word from a string I've generated within another word? It seems like I need to put the word in the input buffer and call parse-word, but I haven't discovered how to do that. For example:
: PrintTitle ( group sub -- )
make-subgroup-title \ consumes group & sub, returns caddr and len or cstring somehow-invoke-the-word-that-text-represents \ returns caddr len
type ;
I can write make-subgroup-title, but do not understand how to write somehow-invoke-the-word-that-text-represents.
Thanks for your time!
But my question is: how can I programmatically execute a word from a string I've generated within another word?
Van Kichline <vkic...@gmail.com> writes:Thanks, all! Evaluate is what I was looking for. 'S" Group2Part3" evaluate type' selects one of many string generators, which I can select by building the word to evaluate.
But my question is: how can I programmatically execute a word from a string I've generated within another word?1) With SEARCH-WORDLIST and EXECUTE
2) With EVALUATE. Note that EVALUATE has some caveats, which may or
may not be relevant in your case <http://www.complang.tuwien.ac.at/forth/why-evaluate-is-bad>.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html New standard: https://forth-standard.org/
EuroForth 2022: https://euro.theforth.net
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 22:28:48 |
Calls: | 9,488 |
Calls today: | 7 |
Files: | 13,617 |
Messages: | 6,121,095 |