Krishna Myneni <kris…@ccreweb.org> writes:
>IF ... IF ... ELSE ... ELSE ... THEN THEN
>
>Is this consistent with the standard?
Yes, but
if A if B else C else D THEN THEN
is equivalent to
if A if B D else C then then
and in particular
if A if B swap else C else swap D then then
is also equivalent to
if A if B D else C then then
So one normally would not write code like this. It may be that this
is not the intended code.
OTOH, I have seen code like
swap +
or
does> ;
in production code, so sometimes programmers miss obvious
simplifications; the formatting of the original code may have
contributed to that.
For the code you posted, the simplification would be
over 0< if
dup 0 <= if
nip 0 over 1024 swap - min swap
else \ negative e and n
swap over 1- negate max swap \ limit negative n
then
then \ limit positive n
which can be further simplified (first branch) and unified (second
branch):
over 0< if
dup 0 <= if ( a b
nip 1024 over - 0 min
else \ negative e and n
swap 1 over - max \ limit negative n
then
swap
then \ limit positive n
The similarities between the branches make it plausible that this code
does what is intended.
- 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 2026 CFP: http://www.euroforth.org/ef26/cfp.html