M.Put("Jr_Released", Crsr.GetInt("Jr_Released"))
Dim X As Int = M.Get("Jr_Released")
If X = 1 Then
SB.Append("HOT")
T.Style = ";-fx-control-inner-background:rgba(255,93,84,1)"
.
.
.
Dim m As Map = CreateMap("test": 1)
Log(m.Get("test") = 1)
Shouldn't that object be reflected here? To me it seems to return an integer.Map.Get returns an Object
Dim d As Double = 1
Dim m As Map = CreateMap("test": d)
Log(m.Get("test") = 1) 'fails
Log(1 = m.Get("test")) 'works
Dim X As Long, Y As Byte, Z As String
X = 1
Y = 1
Z = 1
If X = Y Then MsgBox "True" Else MsgBox "False"
If X = Z Then MsgBox "True" Else MsgBox "False"
If Y = Z Then MsgBox "True" Else MsgBox "False"
Z = "1"
If X = Z Then MsgBox "True" Else MsgBox "False"
If Y = Z Then MsgBox "True" Else MsgBox "False"
All of these statements return trueDECLARE @X int = 1, @Y tinyint = 1, @Z nvarchar(5) = 1
if @X = @Y select 'true' else select 'false'
if @X = @Z select 'true' else select 'false'
if @Y = @Z select 'true' else select 'false'
SET @Z = '1'
if @X = @Z select 'true' else select 'false'
if @Y = @Z select 'true' else select 'false'
Sorry for interfering in your conversation, but I have to ask...
Shouldn't that object be reflected here? To me it seems to return an integer.
View attachment 92912
I'm sure this is obvious to you, knowing the internals of it all. But for me, this is so far from obvious that I would classify it as a bug. Don't get me wrong, I do understand your explanation, and I do understand it's not a bug. But that is the point - I do need an explanation to understand it, because I have no clue about the inner workings of the compiler and just looking at it I would say that if A equals B then B should also equal A. But, as you have explained, that is not always the case.The reason that the second one works is that the compiler "knows" that it needs to make a numerical comparison. This is not the case with the first one.B4X:Log(m.Get("test") = 1) 'fails Log(1 = m.Get("test")) 'works
It has nothing to do with it.Got it, Is that why maps are so fast?
You haven't posted the full code. The compiler cannot know in the first case that you are making a numerical comparison so it treats 1.0 (double) and 1 (int) as different values.'m sure this is obvious to you, knowing the internals of it all. But for me, this is so far from obvious that I would classify it as a bug. Don't get me wrong, I do understand your explanation, and I do understand it's not a bug. But that is the point - I do need an explanation to understand it, because I have no clue about the inner workings of the compiler and just looking at it I would say that if A equals B then B should also equal A. But, as you have explained, that is not always the case.
One of the reasons for using VB has always been its ability to coerce data types.
In VBADim X As Long, Y As Byte, Z As String X = 1 Y = 1 Z = 1 If X = Y Then MsgBox "True" Else MsgBox "False" If X = Z Then MsgBox "True" Else MsgBox "False" If Y = Z Then MsgBox "True" Else MsgBox "False" Z = "1" If X = Z Then MsgBox "True" Else MsgBox "False" If Y = Z Then MsgBox "True" Else MsgBox "False"
All of these statements return true
Perhaps a compiler Switch that could coerce values so we don't have to deal with them?
You are making claims for things that you haven't tested...Granted, a lot of that is the learning curve but still, it would be nice if B4X could do better with data types - and NULLS! - I will start another thread on that one.
Dim X As Long, Y As Byte, Z As String
X = 1
Y = 1
Z = 1
If X = Y Then Log("True") Else Log( "False")
If X = Z Then Log( "True") Else Log( "False")
If Y = Z Then Log( "True") Else Log( "False")
Z = "1"
If X = Z Then Log( "True") Else Log( "False")
If Y = Z Then Log( "True") Else Log( "False")
X would be a "field" of a class or custom type).Dim X As Int = M.Get("Jr_Released")
If Crsr.GetInt("Jr_Released") = 1 then
Log("ResultSet.GetInt returns a primitive int value")
Else
Log("ResultSet.GetInt returns an object other than a primitive int. Perhaps an Integer?"
End
For i = 0 To Recs.Size - 1
Dim m As Map = Recs.Get(i)
Select Case m.Get("linetype") ' <--- is a number
Case 0
...
Case 100
...
Case 200
...
End Select
next
For i = 0 To Recs.Size - 1
Dim m As Map = Recs.Get(i)
Dim LineType As Int = m.Get("dalinetype") ' first put in an Int
Select Case LineType
Case 0
...
Case 100
...
Case 200
...
End Select
next
This might actually be a good idea as an extension of the existing Map keyword. Implementing .GetInt(), .GetDouble(), .GetBoolean(), ... next to the normal Get() etc.If Crsr.GetInt("Jr_Released") = 1 then
No, it's not a bug. It relates to this: https://stackoverflow.com/questions/4428774/why-java-does-not-see-that-integers-are-equal and @Erel answered it already withI'm sure this is obvious to you, knowing the internals of it all. But for me, this is so far from obvious that I would classify it as a bug.
At compilation time the compiler doesn't know the type of object that will be returned from Map.Get as it returns an Object which is the base of all types.
Because when you mix primitives with objects, strange things happen.if A equals B then B should also equal A. But, as you have explained, that is not always the case.
Log(m.Get("test") = 1) 'fails
Log(1 = m.Get("test")) 'works
Dim LineType As Int = m.Get("dalinetype") ' first put in an Int
Dim LineType As Int = m.Get("dalinetype") ' first put in an Int
Update #2: Huh? A post disappeared...The bottom line is that you should be careful when the left side of a comparison is an Object type. It is safer to cast it yourself or put it on the right side of the comparison.
Yeah, strange. I'll just assume it was a minor glitch in the matrix and quote Erels missing post anyway.Update #2: Huh? A post disappeared...
I have a naïve question. Considering the fact that so much of B4X is about shielding us from the strange, inner workings of Java, ObjC and whatnot, would it make sense if the compiler helped us out here? I mean, if the compiler sees a comparison where one side is an object and the other is not, and its safer to put it on the right side of the comparison - couldn't the compiler just switch places so that the object is always is on the right side?The bottom line is that you should be careful when the left side of a comparison is an Object type. It is safer to cast it yourself or put it on the right side of the comparison.
Hm. So it may be related to JDBC after all (again, guessing). The only reason I thought it may be involved is that I noticed:If @MrKim can reproduce it in a small project I would be happy to further investigate it as I wasn't able to reproduce it locally.
It is not possible as it will have other side effects. The left side type has semantic meaning.I mean, if the compiler sees a comparison where one side is an object and the other is not, and its safer to put it on the right side of the comparison - couldn't the compiler just switch places so that the object is always is on the right side?
Log("a" = 1) 'string comparison ("a" = "1") = false
Log(1 = "a") 'numeric comparison => crash
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?