From Newsgroup: comp.lang.forth
On 21-09-2026 10:46,
albert@spenarnc.xs4all.nl wrote:
There was a defect reported for ciforth:
If switched to CASE-INSENSITIVE [THEN] is not recognized in
lower case.
There is nothing in [IF] that suggest it must recognize
lower case [then]. Also the implementation in the standard
doesn't do this.
Now ruv got me. [THEN] is supposedly a standard word.
The implementation in the annex fails this.
That leads to the following using a forward definition.
We are not comparing strings, we look up definitions and
they are subject to case-sensitivity:
\ --------------------------------------------
( [IF] ] [ELSE] [THEN] [DEFINED] [UNDEFINED] ) \ AvdH C6sep20
WANT :F
:F SKIPPING ;
: [IF] 0= IF SKIPPING THEN ; IMMEDIATE ISO
: [ELSE] SKIPPING ; IMMEDIATE ISO
: [THEN] ; IMMEDIATE ISO
:R SKIPPING
1 BEGIN NAME DUP WHILE FOUND
DUP '[IF] = IF DROP 1+ ELSE
DUP '[ELSE] = IF DROP 1- DUP IF 1+ THEN ELSE
'[THEN] = IF 1- THEN THEN THEN
?DUP 0= IF EXIT THEN
REPEAT 2DROP DROP ;
: [UNDEFINED] NAME 2DUP WANTED PRESENT 0= ; IMMEDIATE ISO
: [DEFINED] POSTPONE [UNDEFINED] 0= ; IMMEDIATE ISO
\ --------------------------------------------
"2ROT" [UNDEFINED] [IF]
: 2ROT >R >R 2SWAP R> R> 2SWAP ;
[ELSE]
." NOT NEEDED"
[THEN]
1 2 3 4 5 6 2ROT . . . . . . CR
"1 2 3 4 5 6 2rot . . . . . . CR" 'EVALUATE CATCH ERROR
WANT CASE-INSENSITIVE
1 2 3 4 5 6 2rot . . . . . . CR
The test output:
\ --------------------------------------------
albert@sinas2:~/PROJECT/ciriscv$ lina -a
INCLUDE ifdef.frt
2 1 6 5 4 3
1 2 3 4 5 6 2rot ? ciforth ERROR # 10 : NOT A WORD, NOR A NUMBER OR OTHER DENOTATION
2 1 6 5 4 3
OK
\ --------------------------------------------
Maybe the implementation of 2ROT is wrong, but that is not the point.
Now the question for language lawyers:
Why is this implementation of conditional compilation
not compliant? (It isn't!)
Note as an implementer I'm fully entitled to use ciforth
idiosyncrasies to implement or test.
Groetjes Albert
Well, first of all, your "defined" definitions are nor according to Forth-2012:
: [UNDEFINED] NAME 2DUP WANTED PRESENT 0= ; IMMEDIATE ISO
: [DEFINED] POSTPONE [UNDEFINED] 0= ; IMMEDIATE ISO
Which states:
: [DEFINED] BL WORD FIND NIP 0<> ; IMMEDIATE ( E.15.6.2.2530.30)
: [UNDEFINED] BL WORD FIND NIP 0= ; IMMEDIATE ( E.15.6.2.2534)
Although frankly - this is of zero consequence. Your problem is with
[ELSE], which is defined as:
: [ELSE] ( -- )
1 BEGIN \ level
BEGIN BL WORD COUNT DUP WHILE \ level adr len
2DUP S" [IF]" COMPARE 0= IF \ level adr len
2DROP 1+ \ level'
ELSE \ level adr len
2DUP S" [ELSE]" COMPARE 0= IF \ level adr len
2DROP 1- DUP IF 1+ THEN \ level'
ELSE \ level adr len
S" [THEN]" COMPARE 0= IF \ level
1- \ level'
THEN
THEN
THEN ?DUP 0= IF EXIT THEN \ level'
REPEAT 2DROP \ level
REFILL 0= UNTIL \ level
DROP
; IMMEDIATE
Note, it used "COMPARE" -- which is by definition case sensitive. Now --
you got your own implementation, which is not listed -- but I guess it
does "COMPARE" as well. Only you know.
In short, if you want to use conditional compilation, write [IF], [ELSE]
and [THEN] in capitals.
Note in 4tH the whole shebang is case-insensitive. Now, I like lower
case as much as the next person -- and sometimes Camel case even more.
But I expected so much hassle that I decided to drop case sensitivity in
favor of ease of use.
ANS-94, 3.4.2 states "A system shall be capable of finding the
definition names defined by this Standard when they are spelled
with upper-case letters". That's the bottom line.
All uppercase? Yuk! Never in my life. I did too much C between 1987 and
1994 -- and I came to love it. Strangely enough, I write most Forth code
in lower case, but compiler directives (either 4tH specific or ANS) in CAPITALS. Maybe that's a good habit..
BTW, 4tH has a LOT of conditional compilation. I think it works quite
reliably -- and basically it's essential for this implementation to be
viable in the real world. So I don't have too much trouble with
conditional compilation, I must say.
Hans Bezemer
--- Synchronet 3.22a-Linux NewsLink 1.2