• Executing words from generated text

    From Van Kichline@21:1/5 to All on Sun Mar 26 17:08:05 2023
    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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to Van Kichline on Sun Mar 26 22:44:51 2023
    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.
    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!

    Try something along PARSE-NAME EVALUATE

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to minforth on Sun Mar 26 23:12:12 2023
    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:
    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!
    Try something along PARSE-NAME EVALUATE

    Another helper word to separate names within non-empty(!) strings:

    : 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


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From NN@21:1/5 to minforth on Mon Mar 27 04:47:19 2023
    On Monday, 27 March 2023 at 07:12:13 UTC+1, minforth wrote:
    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:
    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!
    Try something along PARSE-NAME EVALUATE
    Another helper word to separate names within non-empty(!) strings:

    : 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

    two thoughts...
    (1) doesnt test for reaching the end of the line.
    (2) SKIP and SCAN may not be standard but most forth have them

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From NN@21:1/5 to Van Kichline on Mon Mar 27 04:43:49 2023
    On Monday, 27 March 2023 at 01:08:07 UTC+1, Van Kichline wrote:
    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!

    (1) If you use evaluate it will make the string into a new buffer.

    (2) You could also ' or ['] a word and execute the token.

    (3) ( addr u ) is preferred over (cstring )
    { where cstring means counted string as opposed to a c-string ending in '\0' }

    (4) 600 is a lot of words.
    If your groups and subgroups are fixed you could do a vectored execution.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Van Kichline on Mon Mar 27 14:59:04 2023
    Van Kichline <vkichline@gmail.com> writes:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Van Kichline@21:1/5 to Anton Ertl on Mon Mar 27 11:16:27 2023
    On Monday, March 27, 2023 at 8:07:56 AM UTC-7, Anton Ertl wrote:
    Van Kichline <vkic...@gmail.com> writes:
    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
    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.

    Rushing ahead yesterday, I built index arrays (tick word comma (repeat)) to look up my words. My total string data comes to ~580 groups and ~80K of text. I believe the indexes add about 5K in 64 bit gForth and save between 3 and 12 evaluations per
    execution of my program.
    The point of this exercise was to be heavy on data and data selection, lighter on calculation. I found two very different approaches; constructing words for querying the dictionary, or constructing array indexes. I imagine I can economize more by using
    anonymous definitions in the arrays.
    I thought leveraging the dictionary for lookups would be a good strategy, but on the order of 1000 items indexes seem simple and efficient. Perhaps if indexes consumed too much of available RAM lookups would be preferable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)