• Hi all, looking for examples for text or gcode parsing.

    From Jose Morales@21:1/5 to All on Thu Oct 6 05:18:57 2022
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jose Morales@21:1/5 to Jose Morales on Thu Oct 6 07:25:45 2022
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    r> here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dave Bucklin@21:1/5 to jem...@gmail.com on Thu Oct 6 07:58:46 2022
    On Thursday, October 6, 2022 at 9:25:47 AM UTC-5, jem...@gmail.com wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    An example of text processing in Forth by Sam Falvo II. https://www.youtube.com/watch?v=mvrE2ZGe-rs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jose Morales@21:1/5 to dave.b...@gmail.com on Thu Oct 6 12:46:39 2022
    Yes, Sam’s videos is one of the best out there to help understand how to get high level programming. I really enjoy his all data is code analogy, his lates FIG presentation is fantastic, I would love to see if he made the other videos for the
    UNSUITABLE project.

    Thanks!

    On Thursday, October 6, 2022 at 4:58:47 PM UTC+2, dave.b...@gmail.com wrote:
    On Thursday, October 6, 2022 at 9:25:47 AM UTC-5, jem...@gmail.com wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    An example of text processing in Forth by Sam Falvo II. https://www.youtube.com/watch?v=mvrE2ZGe-rs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jose Morales@21:1/5 to dave.b...@gmail.com on Thu Oct 6 12:51:46 2022
    Yes, Sam’s videos is one of the best out there to help understand how to get high level programming. I really enjoy his all data is code analogy, his lates FIG presentation is fantastic, I would love to see if he made the other videos for the
    UNSUITABLE project.

    Thanks!
    On Thursday, October 6, 2022 at 4:58:47 PM UTC+2, dave.b...@gmail.com wrote:
    On Thursday, October 6, 2022 at 9:25:47 AM UTC-5, jem...@gmail.com wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    An example of text processing in Forth by Sam Falvo II. https://www.youtube.com/watch?v=mvrE2ZGe-rs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jose Morales@21:1/5 to dave.b...@gmail.com on Thu Oct 6 12:50:25 2022
    Yes, Sam’s videos is one of the best out there to help understand how to get high level programming. I really enjoy his all data is code analogy, his lates FIG presentation is fantastic, I would love to see if he made the other videos for the
    UNSUITABLE project.

    One thing thought, he is doing character based parsing, which I would ideally try to find the words with in the empty space. I guess if you where writing a GCODE application, then you would be evaluating one character at a time, even then, I would still
    like to see a token and work with each one rather that a single character at a time.

    Thanks!

    On Thursday, October 6, 2022 at 4:58:47 PM UTC+2, dave.b...@gmail.com wrote:
    On Thursday, October 6, 2022 at 9:25:47 AM UTC-5, jem...@gmail.com wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    An example of text processing in Forth by Sam Falvo II. https://www.youtube.com/watch?v=mvrE2ZGe-rs

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Jose Morales on Fri Oct 7 13:39:41 2022
    On 7/10/2022 1:25 am, Jose Morales wrote:
    ...
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?

    Not sure what you mean but my 'goto' word is SPLIT :

    \ Split string at character leaving first on top
    : SPLIT ( a u c -- a2 u2 a3 u3 )
    >r 2dup r> scan 2swap 2 pick - ;

    I then use BL SKIP BL SPLIT in a loop to extract and process the tokens
    one by one.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From NN@21:1/5 to jem...@gmail.com on Sun Oct 9 04:20:32 2022
    On Thursday, 6 October 2022 at 13:18:58 UTC+1, jem...@gmail.com wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.

    Can you elaborate further what you mean by "functional use of the stack" ?

    Whats Gcode ? I havent come across this before.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jose Morales@21:1/5 to dxforth on Mon Oct 10 10:37:56 2022
    Ah, thanks… I have to test that…

    On Friday, October 7, 2022 at 4:39:51 AM UTC+2, dxforth wrote:
    On 7/10/2022 1:25 am, Jose Morales wrote:
    ...
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    Not sure what you mean but my 'goto' word is SPLIT :

    \ Split string at character leaving first on top
    : SPLIT ( a u c -- a2 u2 a3 u3 )
    r 2dup r> scan 2swap 2 pick - ;

    I then use BL SKIP BL SPLIT in a loop to extract and process the tokens
    one by one.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to Jose Morales on Tue Oct 11 12:22:40 2022
    On 06/10/2022 15:25, Jose Morales wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    r> here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?

    A problem with using SEARCH to scan a string for single spaces is that
    it will return zero length strings if more than one space occurs between
    the words on the string being SEARCHed.

    Instead of using SEARCH to scan a string you could use the definition of XT-SKIP at:
    https://forth-standard.org/standard/core/PARSE-NAME
    and use the definition of PARSE-NAME as a guide to scanning your source
    string.

    Unfortunately PARSE-NAME only works on the input source line but can be
    used directly. For example given these definitions to split and display
    words in your test string:

    : sw ( "str1" .. "strn" -- x 0 can un .. ca1 u1 )
    parse-name 2>r r@
    if recurse then
    2r>
    ;

    : .words ( x 0 can un .. ca1 u1 -- )
    begin
    dup
    while
    type dup if ." , " then
    repeat 2drop
    ;

    : split-words sw cr .words cr ;
    \ Now try it on your test words
    split-words G1 G100 S100
    G1, G100, S100
    ok

    Which is probably not convenient in practice. A way around this is to
    use a GForth word called EXECUTE-PARSING, for example using the above definitions for SW and .WORDS:

    : split-words ['] sw execute-parsing ;
    \ test it
    s" G1 G100 S100" split-words cr .words cr
    G1, G100, S100
    ok

    The advantage of using PARSE-NAME is that the Forth system text
    interpreter does the scanning for you.

    Unfortunately most Forth systems don't include EXECUTE-PARSING as it
    isn't a standard word but a definition of it in standard Forth can be
    found at: https://github.com/forthy42/gforth/blob/master/compat/execute-parsing.fs

    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to Gerry Jackson on Tue Oct 11 06:50:38 2022
    Gerry Jackson schrieb am Dienstag, 11. Oktober 2022 um 13:22:43 UTC+2:
    On 06/10/2022 15:25, Jose Morales wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    A problem with using SEARCH to scan a string for single spaces is that
    it will return zero length strings if more than one space occurs between
    the words on the string being SEARCHed.

    Instead of using SEARCH to scan a string you could use the definition of XT-SKIP at:
    https://forth-standard.org/standard/core/PARSE-NAME
    and use the definition of PARSE-NAME as a guide to scanning your source string.

    Unfortunately PARSE-NAME only works on the input source line but can be
    used directly. For example given these definitions to split and display
    words in your test string:

    : sw ( "str1" .. "strn" -- x 0 can un .. ca1 u1 )
    parse-name 2>r r@
    if recurse then

    ;

    : .words ( x 0 can un .. ca1 u1 -- )
    begin
    dup
    while
    type dup if ." , " then
    repeat 2drop
    ;

    : split-words sw cr .words cr ;
    \ Now try it on your test words
    split-words G1 G100 S100
    G1, G100, S100
    ok

    Which is probably not convenient in practice. A way around this is to
    use a GForth word called EXECUTE-PARSING, for example using the above definitions for SW and .WORDS:

    : split-words ['] sw execute-parsing ;
    \ test it
    s" G1 G100 S100" split-words cr .words cr
    G1, G100, S100
    ok

    The advantage of using PARSE-NAME is that the Forth system text
    interpreter does the scanning for you.

    Unfortunately most Forth systems don't include EXECUTE-PARSING as it
    isn't a standard word but a definition of it in standard Forth can be
    found at: https://github.com/forthy42/gforth/blob/master/compat/execute-parsing.fs


    Why so complicated?

    : PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;

    \ Test:

    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;

    S" Mary had a little lamb" STRING-EXTRACT
    Mary
    had
    a
    little
    lamb ok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to minf...@arcor.de on Wed Oct 12 09:58:09 2022
    On 11/10/2022 14:50, minf...@arcor.de wrote:
    Gerry Jackson schrieb am Dienstag, 11. Oktober 2022 um 13:22:43 UTC+2:
    On 06/10/2022 15:25, Jose Morales wrote:
    On Thursday, October 6, 2022 at 2:18:58 PM UTC+2, Jose Morales wrote:
    Hi,

    While in my learning Forth journey, I was looking at more functional use of the stack and how to manage common tasks like file parsing.

    GCode seem like a good candidate to leverage to tackle other more complex file types.

    Thanks,

    Jose.
    S <0> ok
    ok
    : splitword here >r 2swap
    begin compiled
    2dup 2,
    2over search
    while dup negate here 2 cells - +!
    2over nip
    repeat
    2drop 2drop
    here over - ( tokens length )
    dup negate allot
    2 cells / ;
    : .tokens 1 ?do dup 2@ type ." , " cell+ cell+ loop 2@ type ;
    s" G1 G100 S100" s" " splitword .tokens G1, G100, S100 ok

    I found a good source in rosettacode, but is there any way to do this better, specially on a buffer rather than the dictionary?
    A problem with using SEARCH to scan a string for single spaces is that
    it will return zero length strings if more than one space occurs between
    the words on the string being SEARCHed.

    Instead of using SEARCH to scan a string you could use the definition of
    XT-SKIP at:
    https://forth-standard.org/standard/core/PARSE-NAME
    and use the definition of PARSE-NAME as a guide to scanning your source
    string.

    Unfortunately PARSE-NAME only works on the input source line but can be
    used directly. For example given these definitions to split and display
    words in your test string:

    : sw ( "str1" .. "strn" -- x 0 can un .. ca1 u1 )
    parse-name 2>r r@
    if recurse then

    ;

    : .words ( x 0 can un .. ca1 u1 -- )
    begin
    dup
    while
    type dup if ." , " then
    repeat 2drop
    ;

    : split-words sw cr .words cr ;
    \ Now try it on your test words
    split-words G1 G100 S100
    G1, G100, S100
    ok

    Which is probably not convenient in practice. A way around this is to
    use a GForth word called EXECUTE-PARSING, for example using the above
    definitions for SW and .WORDS:

    : split-words ['] sw execute-parsing ;
    \ test it
    s" G1 G100 S100" split-words cr .words cr
    G1, G100, S100
    ok

    The advantage of using PARSE-NAME is that the Forth system text
    interpreter does the scanning for you.

    Unfortunately most Forth systems don't include EXECUTE-PARSING as it
    isn't a standard word but a definition of it in standard Forth can be
    found at:
    https://github.com/forthy42/gforth/blob/master/compat/execute-parsing.fs


    Why so complicated?

    I replicated the functionality of the OPs solution which was to:
    - extract all the words from the string saving the (ca u)s in dataspace
    - then to display them in the order in which they occur in the original
    string on the same line with commas between them.


    : PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;

    \ Test:

    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;

    S" Mary had a little lamb" STRING-EXTRACT
    Mary
    had
    a
    little
    lamb ok


    This solves a slightly different problem, it gets the first word,
    displays it, then gets the second word and so on

    Admittedly the final result is the same but I don't know if the OP had a
    good reason for doing it the way he did.

    He seemed concerned about using dataspace to save the (ca u)'s of the
    words to be displayed - my solution shows they can be stacked and
    recursion is a good way to leave them in the correct order on the stack
    for display.

    Whether using recursion and EXECUTE-PARSING is a complicated solution is
    open to argument. Certainly EXECUTE-PARSING is complicated to implement
    but has a well tested solution in standard Forth and is easy to use.

    Anyway an equivalent to your solution is:

    : string-extract
    begin
    parse-name dup
    while
    cr type
    repeat 2drop
    ;

    s" Mary had a little lamb" ' string-extract execute-parsing
    Mary
    had
    a
    little
    lamb ok

    No need for your PARSE-STRING, PARSE-NAME does the job.

    But I forget, real Forthers implement everything from scratch :)

    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to do-not-use@swldwa.uk on Wed Oct 12 14:13:31 2022
    In article <ti5vj2$1e3v5$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    <SNIP>
    This solves a slightly different problem, it gets the first word,
    displays it, then gets the second word and so on

    Admittedly the final result is the same but I don't know if the OP had a
    good reason for doing it the way he did.

    He seemed concerned about using dataspace to save the (ca u)'s of the
    words to be displayed - my solution shows they can be stacked and
    recursion is a good way to leave them in the correct order on the stack
    for display.

    Whether using recursion and EXECUTE-PARSING is a complicated solution is
    open to argument. Certainly EXECUTE-PARSING is complicated to implement
    but has a well tested solution in standard Forth and is easy to use.

    EXECUTE-PARSING is easy to define (in ciforth at least)
    : EXECUTE-PARSING ROT ROT SAVE SET-SRC CATCH RESTORE THROW ;

    Much easier is to use SAVE / RESTORE and SET-SRC itself and
    inside do whatever you want to do .
    SAVE RESTORE is similar to the clunky saving and restoring
    the current input stream with SAVE-INPUT but doesn't leave clutter on the
    data stack.
    SET-SRC make the string passed to it the input stream and
    exits at the end. Much easier to use than EXECUTE-PARSING

    : EVALUATE SAVE SET-SRC 'INTERPRET CATCH RESTORE THROW ;
    without error detection it is
    : EVALUATE SAVE SET-SRC INTERPRET RESTORE ;

    SET-SRC is not invented for this purpose, it is a factor
    of QUIT.


    Anyway an equivalent to your solution is:

    : string-extract
    begin
    parse-name dup
    while
    cr type
    repeat 2drop
    ;

    I have NAME that takes care of trailing and leading white space.
    To split a file into words I can use
    : split-into-strings 0 0 2SWAP GET-FILE SET-SRC
    SAVE BEGIN NAME OVER 0= UNTIL RESTORE 2DROP
    ;
    0 0 is an null string (addr 0 is and empty string)


    --
    Gerry
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to Gerry Jackson on Wed Oct 12 05:03:32 2022
    Gerry Jackson schrieb am Mittwoch, 12. Oktober 2022 um 10:58:12 UTC+2:
    Why so complicated?
    I replicated the functionality of the OPs solution which was to:
    - extract all the words from the string saving the (ca u)s in dataspace
    - then to display them in the order in which they occur in the original string on the same line with commas between them.

    : PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;

    \ Test:

    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;

    S" Mary had a little lamb" STRING-EXTRACT
    Mary
    had
    a
    little
    lamb ok

    This solves a slightly different problem, it gets the first word,
    displays it, then gets the second word and so on

    Admittedly the final result is the same but I don't know if the OP had a
    good reason for doing it the way he did.

    He seemed concerned about using dataspace to save the (ca u)'s of the
    words to be displayed - my solution shows they can be stacked and
    recursion is a good way to leave them in the correct order on the stack
    for display.

    Whether using recursion and EXECUTE-PARSING is a complicated solution is
    open to argument. Certainly EXECUTE-PARSING is complicated to implement
    but has a well tested solution in standard Forth and is easy to use.

    Anyway an equivalent to your solution is:

    : string-extract
    begin
    parse-name dup
    while
    cr type
    repeat 2drop
    ;

    s" Mary had a little lamb" ' string-extract execute-parsing
    Mary
    had
    a
    little
    lamb ok
    No need for your PARSE-STRING, PARSE-NAME does the job.

    But I forget, real Forthers implement everything from scratch :)


    That's it of course, when it is worthwhile. ;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist. PARSE-NAME moves >IN around.

    Dumb little PARSE-STRING does nothing of that sort.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to none albert on Wed Oct 12 06:37:33 2022
    none albert schrieb am Mittwoch, 12. Oktober 2022 um 14:13:34 UTC+2:
    In article <ti5vj2$1e3v5$1...@dont-email.me>,
    Gerry Jackson <do-no...@swldwa.uk> wrote:
    <SNIP>
    This solves a slightly different problem, it gets the first word,
    displays it, then gets the second word and so on

    Admittedly the final result is the same but I don't know if the OP had a >good reason for doing it the way he did.

    He seemed concerned about using dataspace to save the (ca u)'s of the
    words to be displayed - my solution shows they can be stacked and
    recursion is a good way to leave them in the correct order on the stack
    for display.

    Whether using recursion and EXECUTE-PARSING is a complicated solution is >open to argument. Certainly EXECUTE-PARSING is complicated to implement
    but has a well tested solution in standard Forth and is easy to use. EXECUTE-PARSING is easy to define (in ciforth at least)
    : EXECUTE-PARSING ROT ROT SAVE SET-SRC CATCH RESTORE THROW ;

    Much easier is to use SAVE / RESTORE and SET-SRC itself and
    inside do whatever you want to do .
    SAVE RESTORE is similar to the clunky saving and restoring
    the current input stream with SAVE-INPUT but doesn't leave clutter on the data stack.
    SET-SRC make the string passed to it the input stream and
    exits at the end. Much easier to use than EXECUTE-PARSING

    : EVALUATE SAVE SET-SRC 'INTERPRET CATCH RESTORE THROW ;
    without error detection it is
    : EVALUATE SAVE SET-SRC INTERPRET RESTORE ;

    Good. The originally proposed EXECUTE-PARSING should also be surrounded
    by CATCH .. THROW because it does EVALUATE under the hood and the input
    source is thus changed twice.

    But I don't want to be nit-picky. It is a fine example for flexible functional programming in Forth.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to minf...@arcor.de on Wed Oct 12 16:23:38 2022
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.

    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much
    simpler with none of the above being necessary e.g. in my system

    : execute-parsing ( caddr u xt -- ? )
    -rot StringSource openSource ( -- xt ipsource )
    >r catch r> closeSource ( -- x1 x2 exc | ? 0 )
    throw ( -- ? )
    ;

    Where I already had STRINGSOURCE etc defined for EVALUATE. Depends on
    the system design of course


    Dumb little PARSE-STRING does nothing of that sort.



    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to minf...@arcor.de on Wed Oct 12 16:17:02 2022
    "minf...@arcor.de" <minforth@arcor.de> writes:
    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist.

    Apparently what you se is the implementation in standard Forth, which
    has to implement EXECUTE-PARSING in terms of EVALUATE instead of the
    other way round. A proper implementation of EXECUTE-PARSING that uses
    carnal knowledge about the system does not move strings around and
    does not involve any extra wordlist.

    How to get there: Take your existing implementation of EVALUATE, but
    instead of calling the text interpreter inside it, call CATCH; you
    probably have to do some stack shuffling to get the xt to the CATCH
    and to avoid having internal stack items visible when performing the
    CATCH.

    Once you have that, the implementation of EVALUATE becomes trivial.
    In Gforth it is:

    : evaluate ( ... addr u -- ... ) \ core,block
    ['] interpret2 execute-parsing ;

    Where INTERPRET2 is a variant of interpret that includes supports for backtraces:

    : interpret2 ['] interpret bt-rp0-wrapper ;

    - 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 minforth@arcor.de@21:1/5 to Anton Ertl on Wed Oct 12 11:32:19 2022
    Anton Ertl schrieb am Mittwoch, 12. Oktober 2022 um 18:36:24 UTC+2:
    "minf...@arcor.de" <minf...@arcor.de> writes:
    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist.
    Apparently what you se is the implementation in standard Forth, which
    has to implement EXECUTE-PARSING in terms of EVALUATE instead of the
    other way round. A proper implementation of EXECUTE-PARSING that uses
    carnal knowledge about the system does not move strings around and
    does not involve any extra wordlist.

    How to get there: Take your existing implementation of EVALUATE, but
    instead of calling the text interpreter inside it, call CATCH; you
    probably have to do some stack shuffling to get the xt to the CATCH
    and to avoid having internal stack items visible when performing the
    CATCH.

    Once you have that, the implementation of EVALUATE becomes trivial.
    In Gforth it is:

    : evaluate ( ... addr u -- ... ) \ core,block
    ['] interpret2 execute-parsing ;

    Where INTERPRET2 is a variant of interpret that includes supports for backtraces:

    : interpret2 ['] interpret bt-rp0-wrapper ;

    I really appreciate your insights. Actually my EVALUATE does already use
    .. ['] interpret CATCH .. internally; moving that xt upfront would be trivial indeed.
    Now I am waiting for a use case in my work. ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to minf...@arcor.de on Thu Oct 13 12:38:46 2022
    In article <fdd1240b-34e7-45f5-8919-ef6c73094813n@googlegroups.com>, minf...@arcor.de <minforth@arcor.de> wrote:
    Anton Ertl schrieb am Mittwoch, 12. Oktober 2022 um 18:36:24 UTC+2:
    "minf...@arcor.de" <minf...@arcor.de> writes:
    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist.
    Apparently what you se is the implementation in standard Forth, which
    has to implement EXECUTE-PARSING in terms of EVALUATE instead of the
    other way round. A proper implementation of EXECUTE-PARSING that uses
    carnal knowledge about the system does not move strings around and
    does not involve any extra wordlist.

    How to get there: Take your existing implementation of EVALUATE, but
    instead of calling the text interpreter inside it, call CATCH; you
    probably have to do some stack shuffling to get the xt to the CATCH
    and to avoid having internal stack items visible when performing the
    CATCH.

    Once you have that, the implementation of EVALUATE becomes trivial.
    In Gforth it is:

    : evaluate ( ... addr u -- ... ) \ core,block
    ['] interpret2 execute-parsing ;

    Where INTERPRET2 is a variant of interpret that includes supports for
    backtraces:

    : interpret2 ['] interpret bt-rp0-wrapper ;

    I really appreciate your insights. Actually my EVALUATE does already use
    .. ['] interpret CATCH .. internally; moving that xt upfront would be
    trivial indeed.
    Now I am waiting for a use case in my work. ;-)

    The alternative is consider "parsing" as an object, with the data stream
    as hidden data and INTERPRET as a method.
    That leaves the task of INTERPRET deciding whether executing or compiling. Using PREFIX , this doesn't clutter INTERPRET with numbers nor
    exceptions, while allowing the use of denotations (numbers, strings,
    lambda's) in a modular fashion.

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to do-not-use@swldwa.uk on Thu Oct 13 12:25:19 2022
    In article <ti6m5r$1hc6c$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.

    Not in my book. Parsing is in the core. ALLOCATE is a loaded
    facility.


    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much
    simpler with none of the above being necessary e.g. in my system

    Parsing moves the parse pointer around. Big deal. I have PP instead
    of >IN. All of this is totally invisible, if you have the correct
    parsing tools.
    --
    <SNIP>

    Gerry

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to albert on Thu Oct 13 21:43:49 2022
    On 13/10/2022 9:25 pm, albert wrote:
    In article <ti6m5r$1hc6c$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.

    Not in my book. Parsing is in the core. ALLOCATE is a loaded
    facility.


    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much
    simpler with none of the above being necessary e.g. in my system

    Parsing moves the parse pointer around. Big deal. I have PP instead
    of >IN. All of this is totally invisible, if you have the correct
    parsing tools.

    Occam's razor: Given two adequate solutions to a problem, take the least resource-intensive one.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to dxforth on Thu Oct 13 05:08:09 2022
    On Thursday, October 13, 2022 at 12:43:50 PM UTC+2, dxforth wrote:
    On 13/10/2022 9:25 pm, albert wrote:
    In article <ti6m5r$1hc6c$1...@dont-email.me>,
    Gerry Jackson <do-no...@swldwa.uk> wrote:
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.

    Not in my book. Parsing is in the core. ALLOCATE is a loaded
    facility.


    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much
    simpler with none of the above being necessary e.g. in my system

    Parsing moves the parse pointer around. Big deal. I have PP instead
    of >IN. All of this is totally invisible, if you have the correct
    parsing tools.
    Occam's razor: Given two adequate solutions to a problem, take the least resource-intensive one.

    That is not what Occam said :--)

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to none albert on Thu Oct 13 06:21:20 2022
    none albert schrieb am Donnerstag, 13. Oktober 2022 um 12:25:22 UTC+2:
    In article <ti6m5r$1hc6c$1...@dont-email.me>,
    Gerry Jackson <do-no...@swldwa.uk> wrote:
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.
    Not in my book. Parsing is in the core. ALLOCATE is a loaded
    facility.

    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much >simpler with none of the above being necessary e.g. in my system
    Parsing moves the parse pointer around. Big deal. I have PP instead
    of >IN. All of this is totally invisible, if you have the correct
    parsing tools.

    Well.. if you threw >IN out and moved PP in instead, it's a zero-game.

    If you kept >IN, I would guess that you have to add PP to any input
    source specification that has to be saved and restored before and after
    each INCLUDE/LOAD/EVALUATE.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to minf...@arcor.de on Thu Oct 13 15:24:59 2022
    "minf...@arcor.de" <minforth@arcor.de> writes:
    Good. The originally proposed EXECUTE-PARSING should also be surrounded
    by CATCH .. THROW because it does EVALUATE under the hood and the input >source is thus changed twice.

    A competently written EVALUATE ensures itself that the input stream is
    saved and restored.

    You seem to confuse the specification of EXECUTE-PARSING with the
    example implementation in standard Forth. The latter was not
    proposed, it was just published. The specification was proposed for
    (a less costly) implementation in systems.

    - 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 dxforth@21:1/5 to Marcel Hendrix on Fri Oct 14 10:30:51 2022
    On 13/10/2022 11:08 pm, Marcel Hendrix wrote:
    On Thursday, October 13, 2022 at 12:43:50 PM UTC+2, dxforth wrote:
    On 13/10/2022 9:25 pm, albert wrote:
    In article <ti6m5r$1hc6c$1...@dont-email.me>,
    Gerry Jackson <do-no...@swldwa.uk> wrote:
    On 12/10/2022 13:03, minf...@arcor.de wrote:
    But I forget, real Forthers implement everything from scratch:)

    That's it of course, when it is worthwhile.;-)

    AFAICS the proposed EXECUTE-PARSING moves strings around and
    even needs an extra wordlist

    also allocating and freeing memory.

    Not in my book. Parsing is in the core. ALLOCATE is a loaded
    facility.


    . PARSE-NAME moves >IN around.

    Yes but when EXECUTE-PARSING is built into a system it should be much
    simpler with none of the above being necessary e.g. in my system

    Parsing moves the parse pointer around. Big deal. I have PP instead
    of >IN. All of this is totally invisible, if you have the correct
    parsing tools.
    Occam's razor: Given two adequate solutions to a problem, take the least
    resource-intensive one.

    That is not what Occam said :--)

    You're right. It was Brodie applying it. Ref: 'Thinking FORTH' p.60

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to dxforth on Fri Oct 14 06:33:17 2022
    dxforth <dxforth@gmail.com> writes:
    On 13/10/2022 11:08 pm, Marcel Hendrix wrote:
    On Thursday, October 13, 2022 at 12:43:50 PM UTC+2, dxforth wrote:
    Occam's razor: Given two adequate solutions to a problem, take the least >>> resource-intensive one.

    That is not what Occam said :--)

    You're right. It was Brodie applying it. Ref: 'Thinking FORTH' p.60

    Nope. On p. 60 Brodie claims that the origin is an old saying, and
    gives this wording:

    |Given two solutions to a problem, the correct one is the simpler.

    On p. 61 the illustration is captioned with a slight variation:

    |Given two adequate solutions, the correct one is the simpler.

    The thing about "the least resource-intensive one" seems to be a
    dxforth interpretation, although it does not even decide the case of STRING-EXTRACT using PARSE-STRING vs. PARSE-NAME, as one uses more of
    one resource, and the other uses more of a different resource.

    - 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 dxforth@21:1/5 to Anton Ertl on Fri Oct 14 21:21:14 2022
    On 14/10/2022 5:33 pm, Anton Ertl wrote:
    dxforth <dxforth@gmail.com> writes:
    On 13/10/2022 11:08 pm, Marcel Hendrix wrote:
    On Thursday, October 13, 2022 at 12:43:50 PM UTC+2, dxforth wrote:
    Occam's razor: Given two adequate solutions to a problem, take the least >>>> resource-intensive one.

    That is not what Occam said :--)

    You're right. It was Brodie applying it. Ref: 'Thinking FORTH' p.60

    Nope. On p. 60 Brodie claims that the origin is an old saying, and
    gives this wording:

    |Given two solutions to a problem, the correct one is the simpler.

    On p. 61 the illustration is captioned with a slight variation:

    |Given two adequate solutions, the correct one is the simpler.

    The thing about "the least resource-intensive one" seems to be a
    dxforth interpretation, although it does not even decide the case of STRING-EXTRACT using PARSE-STRING vs. PARSE-NAME, as one uses more of
    one resource, and the other uses more of a different resource.

    What's the spec? So far I'm not seeing anything that justifies the
    use of PARSE-NAME and everything associated with that function.
    Similarly it's not clear STRING-EXTRACT is required.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jemo07@gmail.com@21:1/5 to All on Mon Nov 21 13:55:59 2022
    Hi, I missed the emails coming in on this...

    Thank you all for the feedback, Minf... Thank you for the words to extract this... This is really helpful as I did not see the bl word for the ws delimiter. This has solved many more issues I was having with other parts of the code...


    S" G0 F4800 X7.966 Y15.054 Z0.300" STRING-EXTRACT
    G0
    F4800
    X7.966
    Y15.054
    Z0.300 ok
    ok

    I just retook this and I'm implementing the words to properly capture STRINGS and evaluate for error as Gary mentioned but I can seem to get the file open working... file is a single line like the example provide with a staring FILE read.

    : srcfile S" ./sample.g" ;

    PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;

    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;
    : READFILE srcfile r/o open-file throw
    begin here 1024 read-file throw dup allot
    STRING-EXTRACT 0= until ;
    ok
    readfile
    :36: Invalid memory address
    readfile<<<
    Backtrace:
    $7F8CBAF8F1D0 read-file
    ok

    I'll keep at it, but can't seem to get it to work and I crashing forth :D

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jemo07@gmail.com@21:1/5 to jem...@gmail.com on Mon Nov 21 14:08:18 2022
    On Monday, November 21, 2022 at 10:56:01 PM UTC+1, jem...@gmail.com wrote:
    Hi, I missed the emails coming in on this...

    Thank you all for the feedback, Minf... Thank you for the words to extract this... This is really helpful as I did not see the bl word for the ws delimiter. This has solved many more issues I was having with other parts of the code...


    S" G0 F4800 X7.966 Y15.054 Z0.300" STRING-EXTRACT
    G0
    F4800
    X7.966
    Y15.054
    Z0.300 ok
    ok

    I just retook this and I'm implementing the words to properly capture STRINGS and evaluate for error as Gary mentioned but I can seem to get the file open working... file is a single line like the example provide with a staring FILE read.

    : srcfile S" ./sample.g" ;
    PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;
    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;
    : READFILE srcfile r/o open-file throw
    begin here 1024 read-file throw dup allot
    STRING-EXTRACT 0= until ;
    ok
    readfile
    :36: Invalid memory address
    readfile<<<
    Backtrace:
    $7F8CBAF8F1D0 read-file
    ok

    I'll keep at it, but can't seem to get it to work and I crashing forth :D


    Never mind, I just found this! https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Files-Tutorial.html

    Anton, the work into gforth is amazing!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to SpainHackForth on Mon Nov 21 23:02:30 2022
    SpainHackForth schrieb am Montag, 21. November 2022 um 22:56:01 UTC+1:
    Hi, I missed the emails coming in on this...

    Thank you all for the feedback, Minf... Thank you for the words to extract this... This is really helpful as I did not see the bl word for the ws delimiter. This has solved many more issues I was having with other parts of the code...


    S" G0 F4800 X7.966 Y15.054 Z0.300" STRING-EXTRACT
    G0
    F4800
    X7.966
    Y15.054
    Z0.300 ok
    ok

    I just retook this and I'm implementing the words to properly capture STRINGS and evaluate for error as Gary mentioned but I can seem to get the file open working... file is a single line like the example provide with a staring FILE read.

    : srcfile S" ./sample.g" ;
    PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;
    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;
    : READFILE srcfile r/o open-file throw
    begin here 1024 read-file throw dup allot
    STRING-EXTRACT 0= until ;
    ok
    readfile
    :36: Invalid memory address
    readfile<<<
    Backtrace:
    $7F8CBAF8F1D0 read-file
    ok

    I'll keep at it, but can't seem to get it to work and I crashing forth :D

    use READ-LINE (and close the file when done).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to SpainHackForth on Tue Nov 22 21:10:46 2022
    On 22/11/2022 8:44 pm, SpainHackForth wrote:
    [...]
    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???

    Try

    : READFILE srcfile r/o OPEN-FILE THROW to fd-in
    BEGIN line-buffer DUP max-line fd-in READ-LINE THROW
    WHILE STRING-EXTRACT REPEAT 2DROP
    fd-in CLOSE-FILE THROW ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SpainHackForth@21:1/5 to minf...@arcor.de on Tue Nov 22 01:44:06 2022
    On Tuesday, November 22, 2022 at 8:02:31 AM UTC+1, minf...@arcor.de wrote:
    SpainHackForth schrieb am Montag, 21. November 2022 um 22:56:01 UTC+1:
    Hi, I missed the emails coming in on this...

    Thank you all for the feedback, Minf... Thank you for the words to extract this... This is really helpful as I did not see the bl word for the ws delimiter. This has solved many more issues I was having with other parts of the code...


    S" G0 F4800 X7.966 Y15.054 Z0.300" STRING-EXTRACT
    G0
    F4800
    X7.966
    Y15.054
    Z0.300 ok
    ok

    I just retook this and I'm implementing the words to properly capture STRINGS and evaluate for error as Gary mentioned but I can seem to get the file open working... file is a single line like the example provide with a staring FILE read.

    : srcfile S" ./sample.g" ;
    PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;
    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;
    : READFILE srcfile r/o open-file throw
    begin here 1024 read-file throw dup allot
    STRING-EXTRACT 0= until ;
    ok
    readfile
    :36: Invalid memory address
    readfile<<<
    Backtrace:
    $7F8CBAF8F1D0 read-file
    ok

    I'll keep at it, but can't seem to get it to work and I crashing forth :D
    use READ-LINE (and close the file when done).
    So close, yet so far...

    0 Value fd-in
    256 CONSTANT max-line
    Create line-buffer max-line 2 + allot

    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to SpainHackForth on Tue Nov 22 02:14:08 2022
    SpainHackForth schrieb am Dienstag, 22. November 2022 um 10:44:08 UTC+1:
    So close, yet so far...

    0 Value fd-in
    256 CONSTANT max-line
    Create line-buffer max-line 2 + allot

    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???

    Two hints for the riddle: ;-)

    1) Check your code against the stack diagrams of
    OPEN-FILE \ ( a u fam -- fid ior ) 11.6.1.1970 open named file
    READ-LINE \ ( b u fid -- ur f ior ) 11.6.1.2090 read line from file STRING-EXTRACT \ ( a u -- )

    2) did you set fd-in correctly?

    In case you are using gforth, trace the execution with
    dbg READFILE

    I hope it works, I am no gforth user. For this I would use MinForth, why not? ;-)
    https://sourceforge.net/projects/minforth/files/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to jem...@gmail.com on Tue Nov 22 12:13:19 2022
    In article <bccd44e3-8ed7-4a56-aeb2-2d068ac57938n@googlegroups.com>, jem...@gmail.com <jemo07@gmail.com> wrote:
    Hi, I missed the emails coming in on this...

    Thank you all for the feedback, Minf... Thank you for the words to extract this... This is really helpful as I did not see the bl word for the
    ws delimiter. This has solved many more issues I was having with other parts of the code...


    S" G0 F4800 X7.966 Y15.054 Z0.300" STRING-EXTRACT
    G0
    F4800
    X7.966
    Y15.054
    Z0.300 ok
    ok

    I just retook this and I'm implementing the words to properly capture STRINGS and evaluate for error as Gary mentioned but I can seem to get
    the file open working... file is a single line like the example provide with a staring FILE read.

    : srcfile S" ./sample.g" ;

    PARSE-STRING \ ( a u -- a' u' ap up ) parse ws-delimited string within given string (a u)
    BEGIN over c@ bl > 0= over and
    WHILE 1- swap 1+ swap
    REPEAT over >r
    BEGIN over c@ bl > over and
    WHILE 1- swap 1+ swap
    REPEAT over r@ - r> swap ;

    : STRING-EXTRACT \ ( a u -- )
    BEGIN dup WHILE
    parse-string cr type
    REPEAT 2drop ;
    : READFILE srcfile r/o open-file throw
    begin here 1024 read-file throw dup allot
    STRING-EXTRACT 0= until ;
    ok
    readfile
    :36: Invalid memory address
    readfile<<<
    Backtrace:
    $7F8CBAF8F1D0 read-file
    ok

    If the compiler spits this back at you, are you tempted to
    check whether the parameters passed to `read-file are wrong?


    I'll keep at it, but can't seem to get it to work and I crashing forth :D


    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SpainHackForth@21:1/5 to dxforth on Tue Nov 22 07:24:28 2022
    On Tuesday, November 22, 2022 at 11:10:48 AM UTC+1, dxforth wrote:
    On 22/11/2022 8:44 pm, SpainHackForth wrote:
    [...]
    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???
    Try

    : READFILE srcfile r/o OPEN-FILE THROW to fd-in
    BEGIN line-buffer DUP max-line fd-in READ-LINE THROW
    WHILE STRING-EXTRACT REPEAT 2DROP
    fd-in CLOSE-FILE THROW ;

    ah, missing 2drop was killing me! Thank you!
    Quick question:
    when I do this...
    s" ./sample.g" r/o open-file ok
    S. <2>93873986665184 0 ok
    So I'm getting wfileid wior ... somehow I had 4 items on the stack ( which has been fixed as I was reviewing and writing ... 2DROP fixed this. )
    Ok so two items on the stack, throw consumes TOS, in this case 0, OK getting the wfield TOS and "to" fd-in again to continue the file operation.

    Also, the WHILE ... REPEAT, does that have any control on finish... I see E5.54714 ok
    This is the last entry, so there is no EOF... or is that one of the flags...

    Where do I read the reference all the different stack comments? I'm still not 100% on read-line
    read-line c_addr u1 wfileid – u2 flag wior file “read-line”


    Thank you!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to SpainHackForth on Tue Nov 22 07:34:25 2022
    SpainHackForth schrieb am Dienstag, 22. November 2022 um 16:24:30 UTC+1:
    On Tuesday, November 22, 2022 at 11:10:48 AM UTC+1, dxforth wrote:
    On 22/11/2022 8:44 pm, SpainHackForth wrote:
    [...]
    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???
    Try

    : READFILE srcfile r/o OPEN-FILE THROW to fd-in
    BEGIN line-buffer DUP max-line fd-in READ-LINE THROW
    WHILE STRING-EXTRACT REPEAT 2DROP
    fd-in CLOSE-FILE THROW ;
    ah, missing 2drop was killing me! Thank you!
    Quick question:
    when I do this...
    s" ./sample.g" r/o open-file ok
    S. <2>93873986665184 0 ok
    So I'm getting wfileid wior ... somehow I had 4 items on the stack ( which has been fixed as I was reviewing and writing ... 2DROP fixed this. )
    Ok so two items on the stack, throw consumes TOS, in this case 0, OK getting the wfield TOS and "to" fd-in again to continue the file operation.

    Also, the WHILE ... REPEAT, does that have any control on finish... I see E5.54714 ok
    This is the last entry, so there is no EOF... or is that one of the flags...

    Where do I read the reference all the different stack comments? I'm still not 100% on read-line
    read-line c_addr u1 wfileid – u2 flag wior file “read-line”


    Thank you!

    THE reference:
    http://www.forth200x.org/documents/forth-2012.pdf

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to SpainHackForth on Wed Nov 23 11:19:35 2022
    On 23/11/2022 2:24 am, SpainHackForth wrote:
    On Tuesday, November 22, 2022 at 11:10:48 AM UTC+1, dxforth wrote:
    On 22/11/2022 8:44 pm, SpainHackForth wrote:
    [...]
    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???
    Try

    : READFILE srcfile r/o OPEN-FILE THROW to fd-in
    BEGIN line-buffer DUP max-line fd-in READ-LINE THROW
    WHILE STRING-EXTRACT REPEAT 2DROP
    fd-in CLOSE-FILE THROW ;

    ah, missing 2drop was killing me! Thank you!
    Quick question:
    when I do this...
    s" ./sample.g" r/o open-file ok
    S. <2>93873986665184 0 ok
    So I'm getting wfileid wior ... somehow I had 4 items on the stack ( which has been fixed as I was reviewing and writing ... 2DROP fixed this. )
    Ok so two items on the stack, throw consumes TOS, in this case 0, OK getting the wfield TOS and "to" fd-in again to continue the file operation.

    Also, the WHILE ... REPEAT, does that have any control on finish...

    WHILE ( not EOF) STRING-EXTRACT REPEAT is repeated for each text line in your file

    I see
    E5.54714 ok
    This is the last entry, so there is no EOF... or is that one of the flags...

    Where do I read the reference all the different stack comments? I'm still not 100% on read-line
    read-line c_addr u1 wfileid – u2 flag wior file “read-line”

    flag=0 returned by READ-LINE means EOF was reached

    Here's the code with intermediate stack comments shown. It's a good idea doing this
    until you are familiar with what each word does/expects.

    : READFILE srcfile r/o OPEN-FILE ( fid ior) THROW ( fid) to fd-in
    BEGIN line-buffer DUP max-line fd-in
    ( buf buf maxlen fid) READ-LINE ( buf len flag ior) THROW
    ( buf len flag) WHILE \ not EOF
    ( buf len) STRING-EXTRACT REPEAT
    ( buf len) 2DROP
    fd-in CLOSE-FILE THROW ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to minf...@arcor.de on Wed Nov 23 12:00:48 2022
    "minf...@arcor.de" <minforth@arcor.de> writes:
    THE reference:
    http://www.forth200x.org/documents/forth-2012.pdf

    A little more conventient:
    <https://forth-standard.org/standard/words>.

    However, a standard is not a textbook.

    - 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 SpainHackForth@21:1/5 to dxforth on Wed Nov 23 05:34:47 2022
    On Wednesday, November 23, 2022 at 1:19:37 AM UTC+1, dxforth wrote:
    On 23/11/2022 2:24 am, SpainHackForth wrote:
    On Tuesday, November 22, 2022 at 11:10:48 AM UTC+1, dxforth wrote:
    On 22/11/2022 8:44 pm, SpainHackForth wrote:
    [...]
    : READFILE srcfile r/o fd-in OPEN-FILE THROW
    BEGIN line-buffer max-line fd-in READ-LINE
    STRING-EXTRACT 0=
    UNTIL
    fd-in CLOSE-FILE THROW ;

    Still not working...

    ???
    Try

    : READFILE srcfile r/o OPEN-FILE THROW to fd-in
    BEGIN line-buffer DUP max-line fd-in READ-LINE THROW
    WHILE STRING-EXTRACT REPEAT 2DROP
    fd-in CLOSE-FILE THROW ;

    ah, missing 2drop was killing me! Thank you!
    Quick question:
    when I do this...
    s" ./sample.g" r/o open-file ok
    S. <2>93873986665184 0 ok
    So I'm getting wfileid wior ... somehow I had 4 items on the stack ( which has been fixed as I was reviewing and writing ... 2DROP fixed this. )
    Ok so two items on the stack, throw consumes TOS, in this case 0, OK getting the wfield TOS and "to" fd-in again to continue the file operation.

    Also, the WHILE ... REPEAT, does that have any control on finish...
    WHILE ( not EOF) STRING-EXTRACT REPEAT is repeated for each text line in your file
    I see
    E5.54714 ok
    This is the last entry, so there is no EOF... or is that one of the flags...

    Where do I read the reference all the different stack comments? I'm still not 100% on read-line
    read-line c_addr u1 wfileid – u2 flag wior file “read-line”
    flag=0 returned by READ-LINE means EOF was reached

    Here's the code with intermediate stack comments shown. It's a good idea doing this
    until you are familiar with what each word does/expects.

    : READFILE srcfile r/o OPEN-FILE ( fid ior) THROW ( fid) to fd-in
    BEGIN line-buffer DUP max-line fd-in
    ( buf buf maxlen fid) READ-LINE ( buf len flag ior) THROW
    ( buf len flag) WHILE \ not EOF
    ( buf len) STRING-EXTRACT REPEAT
    ( buf len) 2DROP
    fd-in CLOSE-FILE THROW ;


    That is awesome @dxforth! Thank you for the time you have put in to answer my request.
    Yes, I did not read the Gforth words correctly, and most of my issues where because of unexpected items stack items :)
    I was asking as I could not properly get it working interactively, but I have discover like many tings in Forth, the Leggo can fall apart if you are not careful :D... but it sure as heck is fun... been playing with a single line on to see what I'm doing,
    the Forth way...

    I'm, still seen some stuff on the Stack;

    here 20 dump
    7FCC9B49C160: 47 31 20 58 36 32 2E 30 - 39 38 20 59 31 2E 33 35 G1 X62.098 Y1.35
    7FCC9B49C170: 34 20 45 33 2E 35 35 36 - 35 39 33 2E 35 39 35 39 4 E3.556593.5959
    ok
    ok
    here 30 fh read-line 2drop ok
    .S <1> 1A ok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to SpainHackForth on Thu Nov 24 12:37:11 2022
    On 24/11/2022 12:34 am, SpainHackForth wrote:

    I'm, still seen some stuff on the Stack;

    here 20 dump
    7FCC9B49C160: 47 31 20 58 36 32 2E 30 - 39 38 20 59 31 2E 33 35 G1 X62.098 Y1.35
    7FCC9B49C170: 34 20 45 33 2E 35 35 36 - 35 39 33 2E 35 39 35 39 4 E3.556593.5959
    ok
    ok
    here 30 fh read-line 2drop ok
    .S <1> 1A ok
    Assuming hex mode, you attempted to read a line of up to $30 characters at HERE
    from an opened disk file and got $1A characters (the $1A being left on the stack
    from READ-LINE). Seems reasonable to me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to Anton Ertl on Thu Nov 24 10:50:12 2022
    In article <2022Nov23.130048@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    "minf...@arcor.de" <minforth@arcor.de> writes:
    THE reference:
    http://www.forth200x.org/documents/forth-2012.pdf

    A little more conventient:
    <https://forth-standard.org/standard/words>.

    However, a standard is not a textbook.

    I have looked at it recently. It find it hard to realize
    what has changed, and especially I don't want to overlook
    anything subtle.

    Is there an overview of the changes w.r.t to ISO93?
    A list of paragraphs altered would be great.

    - anton

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to albert@cherry. on Thu Nov 24 10:23:03 2022
    albert@cherry.(none) (albert) writes:
    Is there an overview of the changes w.r.t to ISO93?

    https://forth-standard.org/standard/diff#diff:forth94

    and the following section C.8

    A list of paragraphs altered would be great.

    For that you have to go to

    http://www.forth200x.org/documents/

    and look at the individual drafts, which contain change bars
    (typically against the previous draft).

    - 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 none) (albert@21:1/5 to Anton Ertl on Thu Nov 24 13:06:47 2022
    In article <2022Nov24.112303@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    albert@cherry.(none) (albert) writes:
    Is there an overview of the changes w.r.t to ISO93?

    https://forth-standard.org/standard/diff#diff:forth94

    and the following section C.8

    A list of paragraphs altered would be great.

    For that you have to go to

    http://www.forth200x.org/documents/

    and look at the individual drafts, which contain change bars
    (typically against the previous draft).

    Thank you!

    - anton

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SpainHackForth@21:1/5 to All on Thu Nov 24 08:07:49 2022
    BTW, How does one use parse-name?

    ok
    ok
    .S <0> ok
    S" G1 X25.787 Y2.954 E1.51298" parse-name ok
    .S <4> 55B8AF0B33D0 1A 55B8AF06E351 0 ok
    type ok
    type G1 X25.787 Y2.954 E1.51298 ok
    .S <0> ok

    Also, when I'm using BL it some how works but interactively I feel like like I'm not following the expected output...

    S" G1 X25.787 Y2.954 E1.51298" over c@ bl > 0= over and ok
    .S <3> 55B8AF0B3430 1A 0 ok
    drop type G1 X25.787 Y2.954 E1.51298 ok
    S" G1 X25.787 Y2.954 E1.51298" over c@ bl ok
    .S <4> 55B8AF0B3460 1A 47 20 ok

    What is the 47 left by C@ and 20 left by BL?

    Thank you!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to dave.b...@gmail.com on Thu Nov 24 09:29:23 2022
    On Thursday, October 6, 2022 at 4:58:47 PM UTC+2, dave.b...@gmail.com wrote:
    An example of text processing in Forth by Sam Falvo II. https://www.youtube.com/watch?v=mvrE2ZGe-rs
    Is he really just replacing a handful characters with glyphs - and take an hour for all that?
    I didn't actually get the specs for his program.

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to SpainHackForth on Fri Nov 25 10:59:55 2022
    On 25/11/2022 3:07 am, SpainHackForth wrote:
    BTW, How does one use parse-name?

    Inside a definition.

    : get-tokens ( "ccc ccc ccc" )
    begin parse-name dup while cr type repeat 2drop ;

    get-tokens G1 X25.787 Y2.954 E1.51298
    G1
    X25.787
    Y2.954
    E1.51298 ok

    S" G1 X25.787 Y2.954 E1.51298" over c@ bl ok
    .S <4> 55B8AF0B3460 1A 47 20 ok

    What is the 47 left by C@

    'G'

    and 20 left by BL?

    BL is a standard word. Look up its definition.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dave Bucklin@21:1/5 to the.bee...@gmail.com on Thu Nov 24 16:57:39 2022
    On Thursday, November 24, 2022 at 11:29:25 AM UTC-6, the.bee...@gmail.com wrote:
    Is he really just replacing a handful characters with glyphs - and take an hour for all that?
    I didn't actually get the specs for his program.

    My take is that it's a pretty simple but extensible macro processor. For folks new to Forth, it's a great demonstration of an approach to concatenative programming, though he certainly has his own style.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans Bezemer@21:1/5 to dave.b...@gmail.com on Fri Nov 25 01:06:10 2022
    On Friday, November 25, 2022 at 1:57:41 AM UTC+1, dave.b...@gmail.com wrote:
    My take is that it's a pretty simple but extensible macro processor. For folks new to Forth, it's a great demonstration of an approach to concatenative programming, though he certainly has his own style.
    "Extensible" in the sense you've got to change the code anytime you want to "extend" it.
    And as far as I can see - it becomes slower the more tokens you add. I can say from
    experience that setting it up as a binary search table will greatly improve performance
    if you want to take this thingy seriously.

    https://sourceforge.net/p/forth-4th/wiki/The%204tH%20preprocessor/

    Hans Bezemer

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SpainHackForth@21:1/5 to dxforth on Fri Nov 25 07:39:18 2022
    On Friday, November 25, 2022 at 12:59:59 AM UTC+1, dxforth wrote:
    On 25/11/2022 3:07 am, SpainHackForth wrote:
    BTW, How does one use parse-name?
    Inside a definition.

    : get-tokens ( "ccc ccc ccc" )
    begin parse-name dup while cr type repeat 2drop ;

    get-tokens G1 X25.787 Y2.954 E1.51298
    G1
    X25.787
    Y2.954
    E1.51298 ok

    S" G1 X25.787 Y2.954 E1.51298" over c@ bl ok
    .S <4> 55B8AF0B3460 1A 47 20 ok

    What is the 47 left by C@
    'G'
    and 20 left by BL?
    BL is a standard word. Look up its definition.

    Thank you!
    I did look it up, hens my ask:
    bl – c-char core “b-l”
    c-char is the character value for a space.
    Doh! 0x20...
    I know my biggest gap is grasping the stack notations.

    :D. maybe I wont be so literal next time.
    I know the logic, evaluate until 0x20 but the BL word was throwing me off, I thought it had a more specif function than just been a literal value of 0x20 :D sometimes you just have to look...

    see bl
    32 Constant bl

    I was like, o brother, really? :D, I have to laugh at my self at this point... With Forth, I feel like I'm building a lego blind folded sometimes, I can feel the parts, get an idea how they fit together, but I can't see the colors to know the results where the ones I expect... :D.
    In other words, I was lost in understanding is C@ just pointing to the obvious, first value of the string, therefore 47 is the value, ( could not make that out from the stack comments )
    What is the value 20 just a space, ( or is it Decimal and therefore 14 in HEX) so you see, at first glace it was confusing.
    Ideally I was looking at the code and thinking it was evaluating the Char initial position with C@, then BL would find the next blank space, getting a pointer to the BL location and extracting from position 1 to position 3 ect... I know better now, it's
    just looking for BL and going from there...

    I ran into parse-word, I think I like that option better in terms of usability, not sure is very portable considering maybe will not be available in other Forth.

    Thanks again, it has been an interesting experience, Forth has so many ways to skin a cat, that some times it not obvious to a Noob.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to SpainHackForth on Sat Nov 26 10:01:31 2022
    On 26/11/2022 2:39 am, SpainHackForth wrote:

    I ran into parse-word, I think I like that option better in terms of usability, not sure is very portable considering maybe will not be available in other Forth.

    PARSE-NAME and predecessors PARSE-WORD & WORD form part of the forth interpreter - the
    primary purpose of which is to compile forth source code. Being designed for the latter,
    they require some effort to use in other applications. Such are the issues I rarely -
    if ever - use them, preferring to code parsers from scratch as one would do in other
    languages; and as you did with 'PARSE-STRING'.

    FWIW in my own forth I went as far as segregating the forth compiler entirely - removing
    any temptation to use it in applications. 30 years on, I don't regret that decision in
    the least. While others are fooling around with recognizers and working out how to stop
    users crashing the system, I'm writing apps that are inherently idiot-proof :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ala'a@21:1/5 to All on Sat Nov 26 01:15:05 2022
    Hi,

    I may suggest different way but with a twist. this is a specific to the posted case (GCode), but never the less may be applicable to other cases. take the idea.

    the below steps are based on what I understood may help you:
    1- first pre-process the GCode file to have all commands which take parameters to have a space in between (i.e. X10 -> X 10). simplify the task a little bit.
    2- define words that correspond to all the commands to do what is indented/planned (i.e. lets say X word sets the x variable, so : X x ! ; or maybe move a motor or something suitable to the problem being solved at hand). transform input into runnable
    forth
    3- feed the GCode file as a forth file to a forth compiler/interpreter. hand over the task to Forth to run with it.

    In summary the idea: transfer the source (here GCode) into a runnable Forth words.

    Hope it helps.

    Regards,

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From SpainHackForth@21:1/5 to ama...@gmail.com on Sat Nov 26 08:03:58 2022
    On Saturday, November 26, 2022 at 10:15:07 AM UTC+1, ama...@gmail.com wrote:
    Hi,

    I may suggest different way but with a twist. this is a specific to the posted case (GCode), but never the less may be applicable to other cases. take the idea.

    the below steps are based on what I understood may help you:
    1- first pre-process the GCode file to have all commands which take parameters to have a space in between (i.e. X10 -> X 10). simplify the task a little bit.
    2- define words that correspond to all the commands to do what is indented/planned (i.e. lets say X word sets the x variable, so : X x ! ; or maybe move a motor or something suitable to the problem being solved at hand). transform input into runnable
    forth
    3- feed the GCode file as a forth file to a forth compiler/interpreter. hand over the task to Forth to run with it.

    In summary the idea: transfer the source (here GCode) into a runnable Forth words.

    Hope it helps.

    Regards,
    Hello ama... thanks for the feedback.

    Well, I did not want to go through all those steps overall, parsing a single line seems fast enough for the moment and that is what I'm considering...
    I'm just putting together the words that will, like you mentioned, are the G commands, then I just past the line over to a factored set of "words" that further extract the different variables,
    something like:
    : G20
    ModeG @ if
    setPos@ else
    0 0 0 0 (clear xyz) then
    being $20 parse
    over ( 'F'= ) $46 = if
    do_F else
    over ( 'E'= ) $45 = if
    do_E else
    over ( 'Z'= ) $5A = if
    do_Z else
    over ( 'Y'= ) $59 = if
    do_Y else
    over ( 'X'= ) $58 = if
    do_X else
    then then then then then ;

    I can the have each of the do_ factored out to address what's on the stack...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ruvim@21:1/5 to dxforth on Sun Nov 27 07:48:46 2022
    On 2022-11-25 23:01, dxforth wrote:
    On 26/11/2022 2:39 am, SpainHackForth wrote:

    I ran into parse-word, I think I like that option better in terms of
    usability, not sure is very portable considering maybe will not be
    available in other Forth.

    PARSE-NAME and predecessors PARSE-WORD & WORD form part of the forth interpreter - the
    primary purpose of which is to compile forth source code.  Being
    designed for the latter,
    they require some effort to use in other applications.  Such are the
    issues I rarely -
    if ever - use them, preferring to code parsers from scratch as one would
    do in other
    languages; and as you did with 'PARSE-STRING'.

    FWIW in my own forth I went as far as segregating the forth compiler
    entirely - removing any temptation to use it in applications.

    In Forth, there is no an exact line between extensions of the system and applications.

    OTOH, I usually don't use the Forth compiler in applications, but in
    extensions and DSLs. And actually the Forth compiler is used just to
    create new definitions programmatically.

    Other languages provide similar means by closures and Reflection APIs[1]


    [1] Reflective programming
    https://en.wikipedia.org/wiki/Reflective_programming



    30 years on, I don't regret that decision in the least. While others
    are fooling around with recognizers and working out how to stop
    users crashing the system, I'm writing apps that are inherently
    idiot-proof :)



    --
    Ruvim

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to Ala'a on Sun Nov 27 11:58:25 2022
    In article <ee1d3142-fb13-4d58-9fc0-f75dbcbd0d70n@googlegroups.com>,
    Ala'a <amalawi@gmail.com> wrote:
    Hi,

    I may suggest different way but with a twist. this is a specific to the >posted case (GCode), but never the less may be applicable to other
    cases. take the idea.

    the below steps are based on what I understood may help you:
    1- first pre-process the GCode file to have all commands which take >parameters to have a space in between (i.e. X10 -> X 10). simplify the
    task a little bit.

    If you'd use ciforth, you could define X as a prefix:
    : X whatever .. whenever ; PREFIX

    Regards,


    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andy Valencia@21:1/5 to Dave Bucklin on Tue Nov 29 14:26:24 2022
    Dave Bucklin <dave.bucklin@gmail.com> writes:
    (Forth)
    My take is that it's a pretty simple but extensible macro processor.

    I'd say it's assembly language for a stack based CPU, with a quite decent
    macro facility.

    Andy Valencia
    Home page: https://www.vsta.org/andy/
    To contact me: https://www.vsta.org/contact/andy.html

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