• Conditional compilation

    From dxf@dxforth@gmail.com to comp.lang.forth on Sat Oct 25 22:36:47 2025
    From Newsgroup: comp.lang.forth

    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S


    I'm stunned at how many forths won't handle it. Caught me by surprise.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From minforth@minforth@gmx.net to comp.lang.forth on Sat Oct 25 14:51:35 2025
    From Newsgroup: comp.lang.forth

    Am 25.10.2025 um 13:36 schrieb dxf:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S


    I'm stunned at how many forths won't handle it. Caught me by surprise.

    During compilation I get "unexpected end of file" which is correct
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sun Oct 26 01:17:59 2025
    From Newsgroup: comp.lang.forth

    On 25/10/2025 11:51 pm, minforth wrote:
    Am 25.10.2025 um 13:36 schrieb dxf:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S


    I'm stunned at how many forths won't handle it.  Caught me by surprise.

    During compilation I get "unexpected end of file" which is correct

    The implementation ANS-Forth provides in A.15.6.2.2533 leaves a 1 on the stack albeit undisplayed.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sat Oct 25 16:02:02 2025
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 25/10/2025 11:51 pm, minforth wrote:
    Am 25.10.2025 um 13:36 schrieb dxf:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S
    ...
    The implementation ANS-Forth provides in A.15.6.2.2533 leaves a 1 on the stack >albeit undisplayed.

    Of course there should be a 1 on the stack. There is nothing that
    removes it. There is also nothing that displays it, so it's not
    surprising that it's not displayed.

    When you paste this code in a recent development Gforth, it becomes
    pretty obvious what is happening:

    1 ok 1
    ok 1
    0 [IF] scanning for [THEN]
    scanning for [THEN]
    2 scanning for [THEN]
    scanning for [THEN]
    0 [IF] scanning for [THEN]
    scanning for [THEN]
    3 scanning for [THEN]
    scanning for [THEN]
    [THEN] scanning for [THEN]
    scanning for [THEN]
    .S scanning for [THEN]

    When you put it in a file and include that, you instead get:

    include zzz.fs
    zzz.fs:3:3: warning: unfinished [IF] at end of file ok 1

    The end of the file finishes the [IF] for you in the development
    version (it now says "ok", not "scanning for [THEN]", but not in
    gforth-0.7.

    - 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 2025 CFP: http://www.euroforth.org/ef25/cfp.html
    EuroForth 2025 registration: https://euro.theforth.net/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sun Oct 26 12:03:17 2025
    From Newsgroup: comp.lang.forth

    On 26/10/2025 3:02 am, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 25/10/2025 11:51 pm, minforth wrote:
    Am 25.10.2025 um 13:36 schrieb dxf:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S
    ...
    The implementation ANS-Forth provides in A.15.6.2.2533 leaves a 1 on the stack
    albeit undisplayed.

    Of course there should be a 1 on the stack. There is nothing that
    removes it. There is also nothing that displays it, so it's not
    surprising that it's not displayed.

    When you paste this code in a recent development Gforth, it becomes
    pretty obvious what is happening:

    1 ok 1
    ok 1
    0 [IF] scanning for [THEN]
    scanning for [THEN]
    2 scanning for [THEN]
    scanning for [THEN]
    0 [IF] scanning for [THEN]
    scanning for [THEN]
    3 scanning for [THEN]
    scanning for [THEN]
    [THEN] scanning for [THEN]
    scanning for [THEN]
    .S scanning for [THEN]

    When you put it in a file and include that, you instead get:

    include zzz.fs
    zzz.fs:3:3: warning: unfinished [IF] at end of file ok 1

    The end of the file finishes the [IF] for you in the development
    version (it now says "ok", not "scanning for [THEN]", but not in
    gforth-0.7.

    Yes. I assumed the second 0 [IF] would be ignored.

    What is the correct behaviour for the routine (as given and used in a file)?
    If an 'ambiguous condition' then either an exception (Win32Forth) or leave 1
    on the stack (other Forth) would be valid results.

    In the circumstances that led to this post, I received an obscure 'word not found' error - which wasn't helpful at all. But perhaps all that I can reasonably expect.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 26 08:03:23 2025
    From Newsgroup: comp.lang.forth

    dxf <dxforth@gmail.com> writes:
    On 26/10/2025 3:02 am, Anton Ertl wrote:
    dxf <dxforth@gmail.com> writes:
    On 25/10/2025 11:51 pm, minforth wrote:
    Am 25.10.2025 um 13:36 schrieb dxf:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S
    ...
    ...
    Yes. I assumed the second 0 [IF] would be ignored.

    The question is if you assumed that the [THEN] would finish the first
    [IF]. A system that did that would be non-standard.

    What is the correct behaviour for the routine (as given and used in a file)?

    I can post the specification of [IF], but you can also read it in <https://forth-standard.org/standard/tools/BracketIF>.

    Once the end of the file is reached while the [IF] is not yet
    resolved, it's an ambiguous condition.

    - 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 2025 CFP: http://www.euroforth.org/ef25/cfp.html
    EuroForth 2025 registration: https://euro.theforth.net/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Sun Oct 26 14:10:07 2025
    From Newsgroup: comp.lang.forth

    On 25/10/2025 12:36, dxf wrote:
    Put the following into a file and then load it:

    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S


    I'm stunned at how many forths won't handle it. Caught me by surprise.

    Using the implementation in the standard there are a few strange
    behaviours with [if] e.g putting the above into 1 line for convenience

    1 0 [if] 2 0 [if] 3 [then] \ this [then] .s \ ought to be ignored

    In all Forths I tried the [then] in the comment is found by the first
    [if] control starts interpreting and displays 1 so that the "ought to be ignored" has to be commented out.

    Also:

    [else] can be used as a
    multi-line comment [then]
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Hans Bezemer@the.beez.speaks@gmail.com to comp.lang.forth on Sun Oct 26 15:29:21 2025
    From Newsgroup: comp.lang.forth

    On 4tH, it doesn't even compile:

    $ pp4th -x pptest10.4th
    Compiling; Word 29: Incomplete declaration

    After adding the [THEN]:

    $ pp4th -x pptest10.4th
    1 (TOS)

    Decompile:

    4tH message: Incomplete declaration at word 29
    Object size: 29 words
    String size: 7 chars
    Variables : 0 cells
    Strings : 0 chars
    Symbols : 1 names
    Reliable : No

    Addr| Opcode Operand Argument

    20| rot 0
    21| +literal -1
    22| branch 13
    23| drop 0
    24| ." 0 (TOS)
    25| drop 0
    26| cr 0
    27| exit 0 <<<< end of .S definition
    28| literal 1

    Message: Incomplete declaration (#23 M4NODECL)
    Words: All defining words and compiler directives
    Example: 10 CONSTANT CONSTANT NAME
    Cause: 4. An [IF] is not balanced by a [THEN].

    I forgot all about this thingy!

    Hans Bezemer

    On 25-10-2025 13:36, dxf wrote:
    1

    0 [IF]

    2

    0 [IF]

    3

    [THEN]

    .S

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Sun Oct 26 17:06:14 2025
    From Newsgroup: comp.lang.forth

    Gerry Jackson <do-not-use@swldwa.uk> writes:
    Using the implementation in the standard there are a few strange
    behaviours with [if] e.g putting the above into 1 line for convenience

    1 0 [if] 2 0 [if] 3 [then] \ this [then] .s \ ought to be ignored

    In all Forths I tried the [then] in the comment is found by the first
    [if] control starts interpreting and displays 1 so that the "ought to be >ignored" has to be commented out.

    That's the specified behaviour. One could try to special-case \ ( S"
    etc. in the specifications of [IF] etc., but that would still miss
    other parsing words, including user-defined parsing words.

    One would need a much more involved (and non-traditional) mechanism
    for parsing words in order to avoid that problem.

    But is it a problem? Not in my experience. So I think that the
    current specification is good enough.

    - 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 2025 CFP: http://www.euroforth.org/ef25/cfp.html
    EuroForth 2025 registration: https://euro.theforth.net/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Mon Oct 27 10:54:26 2025
    From Newsgroup: comp.lang.forth

    On 27/10/2025 1:10 am, Gerry Jackson wrote:
    ...
    Also:

    [else] can be used as a
    multi-line comment [then]

    SYNONYM [COMMENT] [ELSE]

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Mon Oct 27 15:30:42 2025
    From Newsgroup: comp.lang.forth

    On 27/10/2025 1:29 am, Hans Bezemer wrote:
    On 4tH, it doesn't even compile:

    $ pp4th -x pptest10.4th
    Compiling;    Word 29: Incomplete declaration

    After adding the [THEN]:

    $ pp4th -x pptest10.4th
    1 (TOS)

    Decompile:

    4tH message: Incomplete declaration at word 29
    Object size: 29 words
    String size: 7 chars
    Variables  : 0 cells
    Strings    : 0 chars
    Symbols    : 1 names
    Reliable   : No

      Addr| Opcode                        Operand   Argument

        20| rot                                 0
        21| +literal                           -1     22| branch                             13     23| drop                                0
        24| ."                                  0   (TOS)
        25| drop                                0
        26| cr                                  0
        27| exit                                0 <<<< end of .S definition
        28| literal                             1

    Message: Incomplete declaration (#23 M4NODECL)
    Words: All defining words and compiler directives
    Example: 10 CONSTANT CONSTANT NAME
    Cause: 4. An [IF] is not balanced by a [THEN].

    I forgot all about this thingy!

    I have to admit to a beginner's mistake. Using screens, [if] [then] almost never
    arises and I got bit. It started with relocating 0 [if] . But instead of deleting
    the original I did this: \ 0 [if]
    From there, it only got worse. Live and learn.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Thu Oct 30 16:24:27 2025
    From Newsgroup: comp.lang.forth

    On 26/10/2025 23:54, dxf wrote:
    On 27/10/2025 1:10 am, Gerry Jackson wrote:
    ...
    Also:

    [else] can be used as a
    multi-line comment [then]

    SYNONYM [COMMENT] [ELSE]

    Yes but, unfortunately the matching
    SYNONYM [END-COMMENT] [THEN]
    to make it more readable and meaningful, won't work with the reference implementation in the ANS Forth standard because string comparisons are carried out when looking for [THEN].

    However with the latest reference implementation of [IF] [ELSE] [THEN]
    see https://forth-standard.org/standard/tools/BracketELSE
    A similar synonym for [END-COMMENT] can work

    At that link scroll down to ruv's suggested reference implementation
    that I've only recently just discovered and which, lower down at that
    link, has apparently been accepted into the next standard that
    supersedes Forth 2012.

    The way to do it exploits a feature of [ELSE] that is true for both implementations of [IF] [THEN] [ELSE].

    If the following is typed into the Forth Interpreter
    [ELSE] 1 [ELSE] 2 [ELSE] 3 [ELSE] 4 [ELSE] 5 [THEN] .S
    it will display 2 4
    The same bizarre behaviour is also true for ELSE and is well known I
    think, but may not be for [ELSE]
    i.e. the 1 3 and 5 are skipped

    Hence [ELSE] ... [ELSE] can be used as a multi-line comment and the
    synonyms are:

    synonym [COMMENT] [ELSE]
    synonym [END-COMMENT] [ELSE]

    This works for both implentations of [IF] [THEN] [ELSE]
    These synonyms assume that [COMMENT] and [END-COMMENT] inherit
    the immediacy of [ELSE] and [THEN] so colon definitions may be
    better

    To demonstrate this the new reference implementation is repeated below
    with additional code inserted and marked with ***

    \ ---------------

    wordlist dup constant bracket-flow-wl get-current swap set-current

    : [if] ( level1 -- level2 ) 1+ ;
    : [else] ( level1 -- level2 ) dup 1 = if 1- then ;
    : [then] ( level1 -- level2 ) 1- ;

    \ Note: the [else] above is only executed by the next definition of
    \ [ELSE] in the Forth wordlist. At that point level1 = 1 so it is
    \ not DUPing an empty stack. This [ELSE] returns 0 to the Forth WL
    \ [ELSE] causing it to terminate.

    get-order bracket-flow-wl swap 1+ set-order \ ***
    synonym [end-comment] [else] \ ***
    : \ postpone \ ; \ *** See note at end
    previous \ ***
    set-current

    : [else] ( -- )
    1 begin begin parse-name dup while
    bracket-flow-wl search-wordlist if
    execute dup 0= if drop exit then
    then
    repeat 2drop refill 0= until drop
    ; immediate

    : [then] ( -- ) ; immediate

    : [if] ( flag -- ) 0= if postpone [else] then ; immediate

    synonym [comment] [else] \ ***

    \ --------------------
    cr .( Tests of [comment] and [end-comment] )

    [comment]
    This is a demonstration of
    a multi-line comment

    which may have blank lines or Forth words in it
    but beware of using bare '[if]' '[else]' or '[then]'
    as they may be executed and may cause you some grief.
    "[comment]" can not be nested
    [end-comment]

    : foo 1234
    [comment] testing immediacy of "[comment]" and "[end-comment]"
    [end-comment]
    2* cr .
    ;
    foo \ displays 2468

    cr .( End of tests)
    \ ------------------------

    Different names can be synonymised with [ELSE] instead of [COMMENT] and [END-COMMENT] which are just used for illustration. Surprisingly (to me
    at least) the existing multi-line comment using parentheses ( and ) can
    be synonyms of [ELSE]. The converse isn't true as [ELSE] has more functionality.

    Of course the standard single line comments, \ and ( , still have their
    place

    Note the the re-definition of \ in the bracket-flow-wl wordlist above
    will prevent [IF] etc being executed in single line \ comments
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Thu Oct 30 20:46:54 2025
    From Newsgroup: comp.lang.forth

    In article <10e03fr$3qgk5$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 26/10/2025 23:54, dxf wrote:
    On 27/10/2025 1:10 am, Gerry Jackson wrote:
    <SNIP>



    Long story short
    - never use nested conditional compilation
    - use [THEN] not [then] , it is a string and there is no
    mention that it is caseinsenstive.
    - use conditional compilation for straight code, never mix
    it with comment, and certainly don't mix it with invented
    comments ( DOC ... ENDDOC , (* *) , \\ , '\* .. *\ )
    - never comment out conditional compilation.


    --
    Gerry
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Thu Oct 30 22:11:47 2025
    From Newsgroup: comp.lang.forth

    On 30/10/2025 16:24, Gerry Jackson wrote:
    Surprisingly (to me at least) the existing multi-line comment using parentheses ( and ) can be synonyms of [ELSE].

    This isn't quite true as ) is not a Forth word, The word ( parses for
    the character ) and so ) need not have space(s) on both sides of it.
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Fri Oct 31 13:45:02 2025
    From Newsgroup: comp.lang.forth

    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    In article <10e03fr$3qgk5$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 26/10/2025 23:54, dxf wrote:
    On 27/10/2025 1:10 am, Gerry Jackson wrote:
    <SNIP>



    Wow, what a lot of advice, some good, some irrelevant. I get the
    impression that you saw that I was using [ELSE] for multi-line comments
    and that I had included the comment code definitions in with the
    conditional code definitions (done for convenience). Then you jumped to
    the conclusion that I was mixing application executable conditional compilation with comments without looking at the code in detail.

    No mixing of the two is involved. I am simply re-using an existing word, [ELSE], which is, therefore, more of a general purpose word that skips
    words in the input stream, it could be called, say, SKIP-WORDS which is
    then redefined [ELSE] or [COMMENT] as appropriate either by colon
    definition or by SYNONYM.

    Long story short
    - never use nested conditional compilation

    Why, occasionally it's useful. Never say never.

    - use [THEN] not [then] , it is a string and there is no
    mention that it is caseinsenstive.

    I fail to see your point, all forth names are strings. Case
    insensitivity or not is a personal preference.

    - use conditional compilation for straight code, never mix
    it with comment

    That depends on what you mean by mix and how much. I see little harm in
    \ or ( comments

    and certainly don't mix it with invented
    comments ( DOC ... ENDDOC , (* *) , \\ , '\* .. *\ )

    Why? I don't understand why you shouldn't use meaningful names for a
    block of comment

    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of
    [IF] etc in the rest of the comment line is not executed
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Fri Oct 31 14:35:24 2025
    From Newsgroup: comp.lang.forth

    Gerry Jackson <do-not-use@swldwa.uk> writes:
    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of
    [IF] etc in the rest of the comment line is not executed

    But the [IF] in the comment may be considered to be active code rather
    than a comment by an outside [IF] or [ELSE].

    Consider

    my-condition [if]
    \ here I have something witty to say about [IF]
    ...
    [else]
    ...
    [then]

    If MY-CONDITION is true, this will work as intended. If MY-CONDITION
    is false, the [IF] in the comment will be perceived as starting an
    [IF] ... [ELSE] ... [THEN] block, and the [ELSE] and the [THEN] will
    be perceived as belonging to it.

    So commenting out parts of conditional compilation has its pitfalls.

    Commenting out a complete [IF]...[THEN] or [IF]...[ELSE]...[THEN]
    block should do ok.

    Note that other parsing words have similar bad effects:

    my-condition [if]
    ." in the [IF] branch"
    [else]
    ." in the [ELSE] branch"
    [then]

    Depending on my-condition, this will have ... interesting effects.

    - 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 2025 CFP: http://www.euroforth.org/ef25/cfp.html
    EuroForth 2025 registration: https://euro.theforth.net/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Fri Oct 31 16:28:21 2025
    From Newsgroup: comp.lang.forth

    Sorry Anton I read your message and was going to reply and I
    accidentally did something that caused Thunderbird to lose your message.
    I can't find it and it isn't in the 'deleted' folder. I'd be grateful if
    you could repost it please.

    From my memory the gist of your message was:
    given

    my-condition [if]
    \ I have something witty to say about [if]
    ....
    [else]
    ....
    [then]

    I think you said that if MY-CONDITION is TRUE then the first [if] let's
    the Forth interpreter take over and so the second [IF] is ignored
    because it's in a comment and all is good

    But if MY-CONDITION is FALSE the second [IF] is reached with unknown consequences.

    With my extension to Ruvim's reference implementation I have inserted
    : \ postpone \ ;
    in the BRACKET-FLOW-WL wordlist (which I hate typing so I'll use the abbreviation BFWL) so when the condition is false the sequence is:
    - The Forth WL [IF] is executed and consumes the false flag to call the
    Forth WL [ELSE]
    - After a refill this [ELSE] parses the \ at the start of the next line
    - it then searches the BFWL, finds \ and executes it to ignore the rest
    of the line including the second [IF]
    - after another REFILL the Forth [ELSE] parses and executes the BFWL
    [ELSE] with 1 on the stack and returns 0 which cause the Forth [ELSE] to
    exit and return control to the Forth interpreter.

    An example worked so I don't see how the second [if] is ever found and executed.

    Or are you saying that the second [if] should be found because that is
    what is expected in a standard by the Forth standard

    Or have I missed some nuance in your message?
    I remember a comment about ." but don't remember anything else
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From anton@anton@mips.complang.tuwien.ac.at (Anton Ertl) to comp.lang.forth on Fri Oct 31 17:12:56 2025
    From Newsgroup: comp.lang.forth

    Gerry Jackson <do-not-use@swldwa.uk> writes:
    Sorry Anton I read your message and was going to reply and I
    accidentally did something that caused Thunderbird to lose your message.
    I can't find it and it isn't in the 'deleted' folder. I'd be grateful if
    you could repost it please.

    It's <2025Oct31.153524@mips.complang.tuwien.ac.at>. You can look it
    up on, e.g., <https://al.howardknight.net/>.

    From my memory the gist of your message was:
    given

    my-condition [if]
    \ I have something witty to say about [if]
    ....
    [else]
    ....
    [then]

    I think you said that if MY-CONDITION is TRUE then the first [if] let's
    the Forth interpreter take over and so the second [IF] is ignored
    because it's in a comment and all is good

    But if MY-CONDITION is FALSE the second [IF] is reached with unknown >consequences.

    The consequences are known, but probably unintended: the [ELSE] and
    [THEN] are perceived as belonging to the second [IF], so at the end
    one is still scanning for the [THEN] or [ELSE] that belongs to the
    first [IF].

    Or are you saying that the second [if] should be found because that is
    what is expected in a standard by the Forth standard

    Yes, a system that ignores [IF] in comments would not be
    standard-conforming, and not in line with existing practice in
    systems.

    Given that nobody will write something like the example above (if
    their system is standard-conformung), does it matter? Let's see if I
    can construct an example that might occur and where it matters:

    my-condition [if]
    .( a)
    [else]
    .( b)
    \ [else]
    .( c)
    [then]
    .( d)

    I tested on gforth 0.7, iforth-5.1 mini, lxf, sf64-4.0.0-rc89, and
    vfx64-5.43. I put the lines above into /tmp/xxx.fs.

    With

    true constant my-condition include /tmp/xxx.fs cr bye

    all systems except iforth output "acd", as specified by the standard.
    iforth outputs "ad", i.e., it has a scanner that treats "\"
    especially. For

    false constant my-condition include /tmp/xxx.fs cr bye

    every system outputs "bcd", as specified by the standard.

    Again, I doubt that anybody will use that intentionally in production
    code. There might be some opccurences by mistake, where, rather than
    fixing the problem (the [ELSE] in text that's not text-interpreted),
    some workaround was implemented. Still, these cases should be so rare
    that a change should be doable, if it was really wanted.

    The bigger problem is that you get the same problem with other parsing
    words. Parsing words can be user-defined, and with search order
    changes one can make things even harder for an [IF] etc. set of words
    that try to be smart about such uses. So where would we stop? Should
    we stop right at the beginning before special-casing any parsing word?

    Or have I missed some nuance in your message?
    I remember a comment about ." but don't remember anything else

    I gave an example where ." was used as a parsing word that parses [IF]
    and [ELSE]. But nothing fundamentally different from the cases
    involving \.

    - 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 2025 CFP: http://www.euroforth.org/ef25/cfp.html
    EuroForth 2025 registration: https://euro.theforth.net/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gerry Jackson@do-not-use@swldwa.uk to comp.lang.forth on Fri Oct 31 20:45:41 2025
    From Newsgroup: comp.lang.forth

    On 31/10/2025 17:12, Anton Ertl wrote:
    Gerry Jackson <do-not-use@swldwa.uk> writes:
    Sorry Anton I read your message and was going to reply and I
    accidentally did something that caused Thunderbird to lose your message.
    I can't find it and it isn't in the 'deleted' folder. I'd be grateful if
    you could repost it please.

    It's <2025Oct31.153524@mips.complang.tuwien.ac.at>. You can look it
    up on, e.g., <https://al.howardknight.net/>.

    From my memory the gist of your message was:
    given

    my-condition [if]
    \ I have something witty to say about [if]
    ....
    [else]
    ....
    [then]

    I think you said that if MY-CONDITION is TRUE then the first [if] let's
    the Forth interpreter take over and so the second [IF] is ignored
    because it's in a comment and all is good

    But if MY-CONDITION is FALSE the second [IF] is reached with unknown
    consequences.

    The consequences are known, but probably unintended: the [ELSE] and
    [THEN] are perceived as belonging to the second [IF], so at the end
    one is still scanning for the [THEN] or [ELSE] that belongs to the
    first [IF].

    Or are you saying that the second [if] should be found because that is
    what is expected in a standard by the Forth standard

    Yes, a system that ignores [IF] in comments would not be
    standard-conforming, and not in line with existing practice in
    systems.

    Given that nobody will write something like the example above (if
    their system is standard-conformung), does it matter? Let's see if I
    can construct an example that might occur and where it matters:

    my-condition [if]
    .( a)
    [else]
    .( b)
    \ [else]
    .( c)
    [then]
    .( d)

    I tested on gforth 0.7, iforth-5.1 mini, lxf, sf64-4.0.0-rc89, and vfx64-5.43. I put the lines above into /tmp/xxx.fs.

    With

    true constant my-condition include /tmp/xxx.fs cr bye

    all systems except iforth output "acd", as specified by the standard.
    iforth outputs "ad", i.e., it has a scanner that treats "\"
    especially. For

    false constant my-condition include /tmp/xxx.fs cr bye

    every system outputs "bcd", as specified by the standard.

    Again, I doubt that anybody will use that intentionally in production
    code. There might be some opccurences by mistake, where, rather than
    fixing the problem (the [ELSE] in text that's not text-interpreted),
    some workaround was implemented. Still, these cases should be so rare
    that a change should be doable, if it was really wanted.

    The bigger problem is that you get the same problem with other parsing
    words. Parsing words can be user-defined, and with search order
    changes one can make things even harder for an [IF] etc. set of words
    that try to be smart about such uses. So where would we stop? Should
    we stop right at the beginning before special-casing any parsing word?

    Or have I missed some nuance in your message?
    I remember a comment about ." but don't remember anything else

    I gave an example where ." was used as a parsing word that parses [IF]
    and [ELSE]. But nothing fundamentally different from the cases
    involving \.


    I removed the definition of \ from the wordlist and, as you would expect
    it gets the same results as all other systems (less iforth).

    So I'll leave it at that, the possibility of there being user defined
    parsing words make it more trouble than it's worth fixing.

    Thanks for the explanation
    --
    Gerry
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Sat Nov 1 00:34:47 2025
    From Newsgroup: comp.lang.forth

    In article <10e2eh0$haak$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    In article <10e03fr$3qgk5$1@dont-email.me>,
    Gerry Jackson <do-not-use@swldwa.uk> wrote:
    On 26/10/2025 23:54, dxf wrote:
    On 27/10/2025 1:10 am, Gerry Jackson wrote:
    <SNIP>



    Wow, what a lot of advice, some good, some irrelevant. I get the
    impression that you saw that I was using [ELSE] for multi-line comments
    and that I had included the comment code definitions in with the
    conditional code definitions (done for convenience). Then you jumped to
    the conclusion that I was mixing application executable conditional >compilation with comments without looking at the code in detail.

    I didn't react. I saw an opportunity to express my thoughts on this.
    To reassure you, I don't kept those rules rigorously.

    --
    Gerry
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sat Nov 1 11:37:16 2025
    From Newsgroup: comp.lang.forth

    On 1/11/2025 12:45 am, Gerry Jackson wrote:
    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    ...
    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of [IF] etc in the rest of the comment line is not executed

    This in fact was my intent during a debug session i.e. the [IF] was moved elsewhere temporarily. I didn't want to delete the original as it was
    always going to be restored - hence my adding a preceding \ (which didn't
    work as I had hoped). I knew what I wanted to do. It's just that the
    existing tools didn't allow me.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Sun Nov 2 11:32:01 2025
    From Newsgroup: comp.lang.forth

    On 1/11/2025 11:37 am, dxf wrote:
    On 1/11/2025 12:45 am, Gerry Jackson wrote:
    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    ...
    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of [IF] etc in the rest of the comment line is not executed

    This in fact was my intent during a debug session i.e. the [IF] was moved elsewhere temporarily. I didn't want to delete the original as it was
    always going to be restored - hence my adding a preceding \ (which didn't work as I had hoped). I knew what I wanted to do. It's just that the existing tools didn't allow me.

    Below is hack that implements it. To what extent it's useful in debugging is for each to determine. I'm less excited about [ELSE] as a comment tool due
    to potential clashes. I have a simple one-liner for that (* *). Again, it's not something a screen user tends to use.

    \ Original
    : [ELSE] ( -- )
    1 BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE

    : [IF] 0= IF POSTPONE [ELSE] THEN ; IMMEDIATE

    : [THEN ; IMMEDIATE

    \ Modified to recognize '\' in skipped code
    : [ELSE] ( -- )
    1 BEGIN BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF [ 1 CS-ROLL ]
    2DUP S" \" COMPARE 0= WHILE 2DROP POSTPONE \ REPEAT
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From albert@albert@spenarnc.xs4all.nl to comp.lang.forth on Sun Nov 2 12:57:44 2025
    From Newsgroup: comp.lang.forth

    In article <6906a681$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
    On 1/11/2025 11:37 am, dxf wrote:
    On 1/11/2025 12:45 am, Gerry Jackson wrote:
    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    ...
    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of [IF] etc in the rest of the comment line is not executed

    This in fact was my intent during a debug session i.e. the [IF] was moved
    elsewhere temporarily. I didn't want to delete the original as it was
    always going to be restored - hence my adding a preceding \ (which didn't
    work as I had hoped). I knew what I wanted to do. It's just that the
    existing tools didn't allow me.

    Below is hack that implements it. To what extent it's useful in debugging is >for each to determine. I'm less excited about [ELSE] as a comment tool due >to potential clashes. I have a simple one-liner for that (* *). Again, it's >not something a screen user tends to use.

    \ Original
    : [ELSE] ( -- )
    1 BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE

    : [IF] 0= IF POSTPONE [ELSE] THEN ; IMMEDIATE

    : [THEN ; IMMEDIATE

    \ Modified to recognize '\' in skipped code
    : [ELSE] ( -- )
    1 BEGIN BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF [ 1 CS-ROLL ]
    2DUP S" \" COMPARE 0= WHILE 2DROP POSTPONE \ REPEAT
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE



    So you use conditional compilation to be able to run your soduku
    solver on e.g. gforth.

    Now you impose conditions how conditional compilation is supposed to
    work on gforth, totally defeating the purpose of using conditional
    compilation to enhance portability.

    Groetjes Albert
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From dxf@dxforth@gmail.com to comp.lang.forth on Mon Nov 3 01:29:21 2025
    From Newsgroup: comp.lang.forth

    On 2/11/2025 10:57 pm, albert@spenarnc.xs4all.nl wrote:
    In article <6906a681$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
    On 1/11/2025 11:37 am, dxf wrote:
    On 1/11/2025 12:45 am, Gerry Jackson wrote:
    On 30/10/2025 19:46, albert@spenarnc.xs4all.nl wrote:
    ...
    - never comment out conditional compilation.

    Why? I've shown that it can be done using \, that means that any use of [IF] etc in the rest of the comment line is not executed

    This in fact was my intent during a debug session i.e. the [IF] was moved >>> elsewhere temporarily. I didn't want to delete the original as it was
    always going to be restored - hence my adding a preceding \ (which didn't >>> work as I had hoped). I knew what I wanted to do. It's just that the
    existing tools didn't allow me.

    Below is hack that implements it. To what extent it's useful in debugging is
    for each to determine. I'm less excited about [ELSE] as a comment tool due >> to potential clashes. I have a simple one-liner for that (* *). Again, it's
    not something a screen user tends to use.

    \ Original
    : [ELSE] ( -- )
    1 BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE

    : [IF] 0= IF POSTPONE [ELSE] THEN ; IMMEDIATE

    : [THEN ; IMMEDIATE

    \ Modified to recognize '\' in skipped code
    : [ELSE] ( -- )
    1 BEGIN BEGIN
    BL WORD COUNT ( 2DUP UPPER) DUP IF [ 1 CS-ROLL ]
    2DUP S" \" COMPARE 0= WHILE 2DROP POSTPONE \ REPEAT
    2DUP S" [IF]" COMPARE IF
    2DUP S" [ELSE]" COMPARE IF
    S" [THEN]" COMPARE 0=
    ELSE 2DROP DUP 1 = THEN
    ELSE 2DROP 1 THEN +
    ELSE 2DROP REFILL AND THEN
    ?DUP 0=
    UNTIL
    ; IMMEDIATE



    So you use conditional compilation to be able to run your soduku
    solver on e.g. gforth.

    Now you impose conditions how conditional compilation is supposed to
    work on gforth, totally defeating the purpose of using conditional compilation to enhance portability.

    I'm not aware ANS-Forth required compatibility with Gforth.

    --- Synchronet 3.21a-Linux NewsLink 1.2