Proposal: Input values other than true and false
This proposal has been moved into this section. Its former address was: /standard/tools/BracketIF
This page is dedicated to discussing this specific proposal
ContributeContributions
AntonErtl
[126] Input values other than true and falseProposal2020-01-11 12:07:07
Problem
"flag" is speficied as:
Flags may have one of two logical states, true or false.
So what happens if you give a value other than true or false to [if]? Looking at the specification, that would be a non-standard program, but without stating that explicitly (and it's probably unintentional).
Existing Practice
Testing a number of Forth systems with the following code:
1 [IF] .( true ) [ELSE] .( false ) [THEN]
Gforth, SwiftForth, VFX, iForth, PFE and lxf output "true", so there is common practice for accepting all non-zero values as true (like IF); (spf apparently does not support [IF]).
Proposal
Replace
( flag | flag "<spaces>name ..." -- )
If flag is true, do nothing.
With
( x | x "<spaces>name ..." -- )
If any bit of x is set, do nothing.