ChatGPT - Stubborn but funnier than many of my former colleagues

LucaMs

Expert
Licensed User
Longtime User
It is certainly stubborn, at least 5 times out of about 30 (?) it used ByRef, even though I explained it... and even for a primitive type parameter (Int).


I tried to make it generate a custom view, a TreeView.
When the project had no syntax errors or others and did not crash, a node, the evil SubChild3, was always placed in the wrong place, at top zero, y zero.

So, after the last attempt I wrote it:

Me:
"Let's see if you can guess where SubChild3is now"

ChatGPT:
"Mmmmm... Let's see... since it was always at Top = 0 before, it's probably still in the wrong position now, but it could:

1. Be under Root, but still out of position.
2. Overlap some other node, maybe under Child2 but above the other children.
3. Be at the top, if something still isn't updating the position correctly.

So... I bet that SubChild3 is now immediately under Root or still at the top! [These are not emojis added by me but by it!]

Tell me, did I guess right or did I make another fool of myself?




[Of course SubChild3 was always in top zero ]
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
It is certainly stubborn, at least 5 times out of about 30 (?) it used ByRef, even though I explained it... and even for a primitive type parameter (Int).
An Italian member had the doubt that, given the very low intelligence of ChatGPT, I had used a version lower than 4.
It was not so, I used that version.
So a little while ago I wanted to do a test, I wanted to see if it learned that in B4X ByRef does not exist.
Here is our chat:

Me:
I wrote a very simple function in B4X language that calculates the area of a square, yet I am told that it contains an error; can you tell me which one? Here is the function:
B4X:
Sub AreaQuadrato(ByRef Lato As Int) As Long
    Return Lato * Lato
End Sub

ChatGPT:
The problem in your function is in the declared return type and the way the function is defined in B4X. In B4X, when you define a subroutine (Sub), it cannot have an explicit return type like As Long. Subroutines in B4X are used to perform actions or operations without returning a specific value.

If you want to calculate the area of a square and return the result, you need to define your function as a Function instead of a Sub. Here's how you could rewrite your function to fix it:
B4X:
Function CalcolaAreaQuadrato(Lato As Int) As Long
    Dim Area As Long
    Area = Lato * Lato
    Return Area
End Function
In this corrected version:
  • I changed Sub to Function to indicate that the function returns a value.
  • I declared a variable Area of type Long to store the result of the calculation.
  • I assigned the result of the Side * Side calculation to the variable Area.
  • I used Return Area to return the value of the calculated area.
Now, when you call this CalculateSquareArea function, you can assign the result to a variable or use it directly in your code, depending on your needs.


Me:
You are wrong. In B4X all Subs are always functions. The only mistake was that in B4X ByRef does not exist and in any case it could not be done for an Int data type.

ChatGPT:
You are right! In B4X all Subs can return a value and there is no distinction between Subs and Functions like in other languages.

The main error in your code is the use of ByRef, which does not exist in B4X. Furthermore, even if it did exist, it could not be applied to a primitive type like Int, because value types are always passed by value and not by reference.

Here is the correct version of your function:
B4X:
Sub AreaQuadrato(Lato As Int) As Long
    Return Lato * Lato
End Sub
This version works perfectly in B4X without any errors. Thanks for the clarification!



I don't know if I should laugh or cry
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…