Am 15.01.21 um 13:44 schrieb Artur Tarassow:
Am 15.01.21 um 12:43 schrieb Riccardo (Jack) Lucchetti:
On Fri, 15 Jan 2021, Artur Bala wrote:
Dear developers,
I thought that the following "if" conditions are supposed to give the
same
results but they actually don't. And the 2nd "if" block ignores "NA"
values
Interesting.
The problem you report can be exemplified even more easily as
<hansl>
scalar z = NA
if z < 0
print "A"
else
print "B"
endif
</hansl>
I'm not sure what we should do in an "if" block if the condition is
neither true or false. At the moment, we treat NA as true (because
it's non-zero), but I wonder if we should throw an error instead.
For instance, the golang compiler say in this situation "non-boolean
condition in if statement" for:
<go>
foo := math.NaN
if foo {
println("something")
}
</go>
I think we should also throw an error.
Ok, let me elaborate on this:
Julia throws "TypeError: non-boolean (Missing) used in boolean context"
<julia>
foo = missing
actual = 0
if foo
actual += 1
end
println(actual)
</julia
Python does not throw an error and returns "1"
<python>
import math
foo = math.nan
actual = 0
if foo:
actual += 1
print(actual)
</python>
So, two of the three languages I used throw an error. Python is known
for its rather "sloppy" handling of types :-D
Artur
_______________________________________________
Gretl-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Website:
https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/