• Re: Fetch string from comment

    From minforth@21:1/5 to sjack on Mon Mar 3 19:44:14 2025
    On Mon, 3 Mar 2025 18:17:01 +0000, sjack wrote:

    om OVER MINUS

    Buddha said, om is boundless wisdom. ;-)

    For us poor novices, could you please share some Forth code
    to show how you have implemented your novel nestable comments?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to sjack on Tue Mar 4 11:14:34 2025
    In article <vq4rmt$1dv1v$1@dont-email.me>, sjack <sdwjack69@gmail.com> wrote:
    String fetched from comment



    Comment string

    ( This string is a simple comment)
    ( The comment can be enhanced to include parethises in the string)

    ( This string is an (enhanced) comment)

    Nested comments is a source of a lot of evil, second only to
    premature optimisation and goto's.

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to All on Tue Mar 4 15:55:09 2025
    second only to premature optimisation and goto's.

    How to code a state-machine without goto's?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to dxf on Tue Mar 4 21:02:52 2025
    dxf <dxforth@gmail.com> wrote:

    Not understanding where it fits in. Is this meant to be in lieu of
    ." ," S" etc ?

    It could be if you were so incline. I'm not suggesting you should but
    showing something possible.

    The case for enhanced (nested) comment:
    Traditionally the first line of an SCR is a comment seen by INDEX :
    ( FOO BAR BAT )
    Traditionally certain words are inclosed in parentheses, i.e. (.") .
    I would like to put such words in the comment seen by INDEX :
    ( FOO (PLUGH) BAR BAT )
    Hence to do so the simple comment is enhanced to allow this.

    Using enhanced comment for string operations:
    If you have it then use it if it suits you.
    The enhanced comment is more robust than the existing string operators
    that you show in that any mix of printable characters can be contained
    in the comment and string operators that base on it. No breaking up
    text nor escaping characters needed (by the Forth):

    .( The function("bar") char ) emit .( is to be used) \ standard, bah
    .( The function("bar") is to be used) \ enhanced, ok
    ." Jack said " char " emit ." boo" char " emit . \ standard, bah
    .( Jack said "boo") \ enhanced, ok
    @( echo -e "Hello World\!") /sys \ enhanced, ok
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to minforth on Tue Mar 4 21:02:49 2025
    minforth <minforth@gmx.net> wrote:

    Buddha said, om is boundless wisdom. ;-)

    It's my favorite Forth word. When I type it, I become at peace.

    For us poor novices, could you please share some Forth code
    to show how you have implemented your novel nestable comments?

    Having a nested comment is nothing new; Forthers been doing it
    long back:
    : (
    ONE BEGIN
    INC@ CASE
    ZERO OF DROP ZERO ENDOF
    ASC ( OF 1+ ENDOF
    ASC ) OF 1- ENDOF
    ENDCASE
    DUP ONE < UNTIL
    DROP ; IMMEDIATE

    What may be new is the idea that if one has it then fetch it
    from the input buffer and use it for string operations.

    : @( PARSE_AREA [COMPILE] ( PARSE_AREA 1- OM ;

    : .( @( TYPE ; \ print it

    : S( @( SIB! ; \ stores in ring buffer

    Didn't bother to generalize the next two:

    Compile single line of text
    : ,(
    ONE BEGIN INC@ TUCK CASE
    ZERO OF 2DROP EXIT ENDOF
    ASC ( OF 1+ ENDOF
    ASC ) OF 1- ENDOF
    ENDCASE DUP WHILE SWAP C, REPEAT 2DROP ;

    -- Compile multiple lines of text
    : ,M(
    ONE BEGIN INC@ TUCK CASE
    ZERO OF SWAP DROP \N SWAP CR REFILL 0= IF ABORT THEN ENDOF
    ASC ( OF 1+ ENDOF
    ASC ) OF 1- ENDOF
    ENDCASE DUP WHILE SWAP C, REPEAT 2DROP ;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to albert@spenarnc.xs4all.nl on Tue Mar 4 21:02:55 2025
    albert@spenarnc.xs4all.nl wrote:

    Nested comments is a source of a lot of evil, second only to
    premature optimisation and goto's.

    Understandable for your case where you are developing and maintaing
    code for use by the general public that you would want to keep KISS
    and avoid at all possible cost of having to bail out some client
    who are apt to get themselves in trouble.
    In my case it poses no problem and I'm sure it won't for many others.
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to All on Wed Mar 5 07:57:24 2025
    For the past 30 years, I got by with having .~ in addition to ." .
    The word .~ does the same ." but uses `~` as its delimiter.
    Most of my uses are served by judicious switching between ."
    and .~ .

    I am not a fan of S\" TYPE as it tends to move the parsing and
    interpretation problems to parts of the code / library that may
    not be prepared for it, or where it would be quite an overhead
    to anticipate every present and future possibility. For instance,
    having a backspace in a string has no obvious meaning in most
    of the system code, and an application can simply redefine BS
    to have it do what is necessary.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to mhx on Wed Mar 5 08:40:04 2025
    mhx@iae.nl (mhx) writes:
    I am not a fan of S\" TYPE as it tends to move the parsing and
    interpretation problems to parts of the code / library that may
    not be prepared for it, or where it would be quite an overhead
    to anticipate every present and future possibility.

    Can you elaborate on that, especially about the overhead?

    For instance,
    having a backspace in a string has no obvious meaning in most
    of the system code

    Nobody forces you you to use \b if it's inappropriate.

    and an application can simply redefine BS
    to have it do what is necessary.

    One would have to define BS first; otherwise you cannot redefine it.
    What is BS supposed to do, and what is redefining BS supposed to
    achieve?

    - 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 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to mhx on Wed Mar 5 12:07:15 2025
    On 04/03/2025 15:55, mhx wrote:
    second only to premature optimisation and goto's.

    How to code a state-machine without goto's?

    -marcel

    A state transition table with an interpreter? See Julian Noble's paper http://galileo.phys.virginia.edu/classes/551.jvn.fall01/fsm.html

    But you probably knew about that so why doesn't it count as gotoless?

    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to dxf on Wed Mar 5 16:00:28 2025
    dxf <dxforth@gmail.com> wrote:
    albeit not idiot-proof ... ( ) needs to be balanced.

    Yes, which is my most use case. An odd-ball unblanced () is still
    workable using the components, adding parenthesis to balance and
    adjusting the count for consumption:

    .( Use this when () are balanced )
    @( Use this when "foo(" left () unblanced)) 1- type

    For me the other issue was non-graphic characters. Unable to avoid it
    I adopted a simplified form of 200x escapes whereby " becomes \22 .

    That's another topic. Could be handled by enhanced comment but perhaps
    better delt with by other means.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to Gerry Jackson on Wed Mar 5 16:50:13 2025
    Gerry Jackson <do-not-use@swldwa.uk> writes:
    On 04/03/2025 15:55, mhx wrote:
    How to code a state-machine without goto's?
    ...
    But you probably knew about that so why doesn't it count as gotoless?

    Does it make a difference in understandability whether you implement a
    state transition as "goto state123" or in the Dijkstra-compatible
    "state = state123"? So why should I care whether it is gotoless?

    --
    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 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to Anton Ertl on Wed Mar 5 17:29:22 2025
    On Wed, 5 Mar 2025 16:50:13 +0000, Anton Ertl wrote:

    Does it make a difference in understandability whether you implement a
    state transition as "goto state123" or in the Dijkstra-compatible
    "state = state123"? So why should I care whether it is gotoless?

    The syntax is fine (the one is just as unreadable as the other) but what
    about the implementation?

    I couldn't locate the pertinent subject at https://www.cs.utexas.edu/~EWD/welcome.html, do you have a hint?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to sjack on Wed Mar 5 18:00:36 2025
    sjack <sjack@dontemail.me> wrote:

    .( Use this when () are balanced )
    @( Use this when "foo(" left () unblanced)) 1- type


    ( Using vocabulary for bacForth style )
    : .(( rtc back 1- type trek @( ;
    : .() rtc back 1 /+- type trek @( ;

    ( For non-diabetics:)
    cr i. .(( foo (bar) "bat(" ))
    foo (bar) "bat("

    cr i. .() (foo (bar) "bat)" )
    foo (bar) "bat)"
    --

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to mhx on Wed Mar 5 19:03:03 2025
    mhx@iae.nl (mhx) writes:
    On Wed, 5 Mar 2025 16:50:13 +0000, Anton Ertl wrote:

    Does it make a difference in understandability whether you implement a
    state transition as "goto state123" or in the Dijkstra-compatible
    "state = state123"? So why should I care whether it is gotoless?

    The syntax is fine (the one is just as unreadable as the other) but what >about the implementation?

    The argument about avoiding gotos have been along the lines that the
    goto makes it hard to understand the program, not that there was a
    problem with implementing it.

    I couldn't locate the pertinent subject at >https://www.cs.utexas.edu/~EWD/welcome.html, do you have a hint?

    https://dl.acm.org/doi/10.1145/362929.362947

    - 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 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@21:1/5 to All on Wed Mar 5 18:29:48 2025
    Here's an example from Clojure:

    (let [saying3 (promise)]
    (future (deliver saying3 (wait 100 "Cheerio!")))
    @(let [saying2 (promise)]
    (future (deliver saying2 (wait 400 "Pip pip!")))
    @(let [saying1 (promise)]
    (future (deliver saying1 (wait 200 "'Ello, gov'na!")))
    (println @saying1)
    saying1)
    (println @saying2)
    saying2)
    (println @saying3)
    saying3)

    But Forth comments? But what do I know...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerry Jackson@21:1/5 to Anton Ertl on Wed Mar 5 19:40:32 2025
    On 05/03/2025 16:50, Anton Ertl wrote:
    Gerry Jackson <do-not-use@swldwa.uk> writes:
    On 04/03/2025 15:55, mhx wrote:
    How to code a state-machine without goto's?
    ...
    But you probably knew about that so why doesn't it count as gotoless?

    Does it make a difference in understandability whether you implement a
    state transition as "goto state123" or in the Dijkstra-compatible
    "state = state123"? So why should I care whether it is gotoless?


    I was just wondering why Marcel apparently cared, not you :)

    --
    Gerry

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to All on Wed Mar 5 23:43:05 2025
    I couldn't locate the pertinent subject at >>https://www.cs.utexas.edu/~EWD/welcome.html, do you have a hint?

    https://dl.acm.org/doi/10.1145/362929.362947

    That was a nice read! I see Dijkstra's argument that a goto as
    we know it is lacking necessary functionality.
    However, a state machine has well defined rules based on a
    state's stored information and its inputs, causing it to go to
    another well-defined state while generating outputs. In that
    context a goto is harmless and merely serves as a crutch when
    there are not enough computing nodes to serve all states in
    parallel. How to make such an efficient crutch in Forth?

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to dxforth@gmail.com on Thu Mar 6 12:14:07 2025
    In article <74a5b61b65b89c594e3f653a0266dc874d6cc739@i2pn2.org>,
    dxf <dxforth@gmail.com> wrote:
    On 5/03/2025 6:57 pm, mhx wrote:
    ...
    I am not a fan of S\" TYPE as it tends to move the parsing and
    interpretation problems to parts of the code / library that may
    not be prepared for it, or where it would be quite an overhead
    to anticipate every present and future possibility.

    What finally drove me to implement escapes was this:

    : RC$ ( -- a n ) \ row/col string
    bin? if s" \00" end s" 000" drop #asc ;

    Every other way of doing it looked like a hack. ... And it solved
    the embedded double-quote problem.

    I don't understand this.
    "every other way to do what?".
    ( -- a n ) i s not a specification.
    If you introduce a word like RC$ tell us what it is supposed to
    do.

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to mhx on Thu Mar 6 12:28:11 2025
    In article <001c29937cf8440ee5cc4a26135820af@www.novabbs.com>,
    mhx <mhx@iae.nl> wrote:
    I couldn't locate the pertinent subject at >>>https://www.cs.utexas.edu/~EWD/welcome.html, do you have a hint?

    https://dl.acm.org/doi/10.1145/362929.362947

    That was a nice read! I see Dijkstra's argument that a goto as
    we know it is lacking necessary functionality.
    However, a state machine has well defined rules based on a
    state's stored information and its inputs, causing it to go to
    another well-defined state while generating outputs. In that
    context a goto is harmless and merely serves as a crutch when
    there are not enough computing nodes to serve all states in
    parallel. How to make such an efficient crutch in Forth?

    The original Turing machine was a bunch of cards with instructions
    manipulating the tape.
    The last instruction was always the next card that you must get
    further instructions.
    As such the goto is underlying any type of stylized instructions.
    That was not what I meant that by
    "nested comment is almost as bad as goto's".
    I really meant that nested comment leads to a lot of confusion
    without redeeming advantages.


    -marcel

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Anton Ertl@21:1/5 to mhx on Thu Mar 6 18:09:30 2025
    mhx@iae.nl (mhx) writes:
    However, a state machine has well defined rules based on a
    state's stored information and its inputs, causing it to go to
    another well-defined state while generating outputs. In that
    context a goto is harmless and merely serves as a crutch when
    there are not enough computing nodes to serve all states in
    parallel. How to make such an efficient crutch in Forth?

    You lost me. Why would one "serve all states in parallel"?

    Anyway, if the question is how to implement a state machine
    efficiently in Forth, one answer is to stay at a higher, more
    structured level of abstraction or recreate it from the state machine.
    E.g., don't transform a regular expression into a (indeterministic or deterministic) finite state machine, but instead interpret it directly
    (that's what Bernd Paysan's regexp.fs does). Or instead of
    transforming a grammar into a push-down automaton, transform it into a structured Forth program (like Gray does).

    If you cannot do that, in standard Forth you don't really have good
    options. The best is probably to have the current state on the stack
    (probably in the form of the address of an array indexed with the
    input (or whatever causes a state change) and containing the potential
    next states at the appropriate elements.

    In a particular implementation, you can do more, including goto-like
    things. What I would do then is have a colon definition per state,
    and do the transition to the next state as tail call. Have some
    efficient forward-tail-call mechanism to allow calling states where
    the definition comes later. Gforth has a clever FORWARD, but for now
    that does not do tail-calls.

    - 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 2023 proceedings: http://www.euroforth.org/ef23/papers/
    EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From sjack@21:1/5 to sjack on Fri Mar 7 02:10:42 2025
    sjack <sjack@dontemail.me> wrote:
    String fetched from comment



    Notes


    i. Print "-->"
    ul(...) Underline output of enclosed code
    tell COUNT TYPE
    om OVER MINUS

    -fin-
    Note The underline didn't show in the post.


    OOPS, not MINUS but -
    : OM ( a1 a2 -- a1 u ) OVER - ;

    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to Anton Ertl on Fri Mar 7 08:27:33 2025
    On Thu, 6 Mar 2025 18:09:30 +0000, Anton Ertl wrote:

    mhx@iae.nl (mhx) writes:
    However, a state machine has well defined rules based on a
    state's stored information and its inputs, causing it to go to
    another well-defined state while generating outputs. In that
    context a goto is harmless and merely serves as a crutch when
    there are not enough computing nodes to serve all states in
    parallel. How to make such an efficient crutch in Forth?

    You lost me. Why would one "serve all states in parallel"?

    I was thinking on running a special kind of application
    (circuit simulation) on a GPU. [It is possible to transform
    circuits into a (big) digital wave filte (DWF, Fettweis).
    The advantage is that computation is parallel, with one
    result per clock cycle (no iteration needed). Because of
    the clock, the computations on each node can be done in
    parallel.]

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to Anton Ertl on Fri Mar 7 14:52:02 2025
    In article <2025Mar5.094004@mips.complang.tuwien.ac.at>,
    Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
    mhx@iae.nl (mhx) writes:
    I am not a fan of S\" TYPE as it tends to move the parsing and >>interpretation problems to parts of the code / library that may
    not be prepared for it, or where it would be quite an overhead
    to anticipate every present and future possibility.

    Can you elaborate on that, especially about the overhead?

    For instance,
    having a backspace in a string has no obvious meaning in most
    of the system code

    Nobody forces you you to use \b if it's inappropriate.

    That is not the problem with escapes.
    The problem comes if you use "\b" where it is meant literal
    and it is altered.
    So beside adhering to ISO, the string constant in style
    "orang utan@@\a\b\q#$^^&**()^*()_+" are absolutely literal
    in ciforth. The "-prefix was a pre-20xx extension.
    Only exception is the doubling of the double quotes, Algol68 style. "orang""UTAN" replace "orang\"UTAN" without the possibility of
    confusion.


    and an application can simply redefine BS
    to have it do what is necessary.

    One would have to define BS first; otherwise you cannot redefine it.
    What is BS supposed to do, and what is redefining BS supposed to
    achieve?

    Good questions.
    My idea of a prefix that does special parsing:
    1. it is part of the application and documented there
    2. User defined notation must not be recognized in the minimum defined
    search order, such like numbers. Instead it belongs in Forth or another wordlist and is forgettable, marked-offable.

    In this context these questions are easily answered.


    - anton

    Groetjes Albert
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

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