Large compiler refactoring

Magma

Expert
Licensed User
Longtime User
Just finished a large refactoring related to the way variables and parameters are handled internally. Zero effect on B4X code behavior, but will make it easier to introduce new features. More to come...
Can we count that will also have a runtime module runner ?

or I am asking too much ;-) ?

addB4XPage("mymodule1.bas","myModule") 'or at least a jar...
addJserverHandler("mymodule1.bas","myModule") 'or at least a jar...

ps: You can count it as wish 💕
 

Cableguy

Expert
Licensed User
Longtime User
B4X:
'class method
Public Sub Example(x As Object = Me, y As Int = 4)

'calling:
Object1.Example
'compiler completes it as if the code is:
Object1.Example(Me, 4)
And if we need Object1.example(notMe as objet, y=8)?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm sure that you already got the point but here is another example 😅:

Null. Null. Null.
B4X:
    Dim RunningCalls As List = OkHttpClient.RunMethodJO("dispatcher", Null).RunMethod("runningCalls", Null)
    For Each call As JavaObject In RunningCalls
        Dim req As JavaObject = call.RunMethod("request", Null)
        Dim s As String = req.RunMethod("url", Null)
        If s = URL Then
            call.RunMethod("cancel", Null)
            Return
        End If
    Next

Now:
B4X:
Dim RunningCalls As List = OkHttpClient.RunMethodJO("dispatcher").RunMethod("runningCalls")
For Each call As JavaObject In RunningCalls
    Dim req As JavaObject = call.RunMethod("request")
    Dim s As String = req.RunMethod("url")
    If s = URL Then
        call.RunMethod("cancel")
        Return
    End If
Next

I had plans to also add a "varargs" feature as an optional replacement to Array(...) usages, however this will not be included for now due to too many problematic edge cases.
 

aaronk

Well-Known Member
Licensed User
Longtime User
What about if you want to only pass one parameter and use the default for others ?

I assume you need to either include none and use the default for all, include the first one, or pass all parameters ?


B4X:
'class method
Public Sub Example(x As Object = Me, y As Int = 4, x As int = 22)

' Use all defaults
Object1.Example

' Only include the first one, and the rest use the default
Object.Example(me)

' Include all
Object.Example(me,5,10)

' how would we include one parameter and use the default for the rest ?
Object.Example(34) ' example: 34 = x, and use default for the rest
 

Daestrum

Expert
Licensed User
Longtime User
What about if you want to only pass one parameter and use the default for others ?

I assume you need to either include none and use the default for all, include the first one, or pass all parameters ?


B4X:
'class method
Public Sub Example(x As Object = Me, y As Int = 4, x As int = 22)

' Use all defaults
Object1.Example

' Only include the first one, and the rest use the default
Object.Example(me)

' Include all
Object.Example(me,5,10)

' how would we include one parameter and use the default for the rest ?
Object.Example(34) ' example: 34 = x, and use default for the rest
Confused me as you used x twice, but I see what you mean
In most languages defaults are to the right (unless it has named parameters)
so in your example 'x' being the last variable, you need to supply all the parameters before it.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
In most languages defaults are to the right (unless it has named parameters)
so in your example 'x' being the last variable, you need to supply all the parameters before it.
That's true.
B4X:
Private Sub Example(A As Int = 1, B As String = "b", C As Button = Null)

You can call it:
B4X:
Example
Example(22)
Example(22, "bb")
Example(22, "bb", Button3)
 

cklester

Well-Known Member
Licensed User
What about if you want to only pass one parameter and use the default for others ?

B4X:
'class method
Public Sub Example(x As Object = Me, y As Int = 4, x As int = 22)

' Use all defaults
Object1.Example

' Only include the first one, and the rest use the default
Object.Example(me)

' Include all
Object.Example(me,5,10)

' how would we include one parameter and use the default for the rest ?
Object.Example(34) ' example: 34 = x, and use default for the rest

Best case scenario is we will be able to do

B4X:
Object.Example(x=10) 'the rest are defaulted
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1787754291638.png
 

Star-Dust

Expert
Licensed User
Longtime User
Best case scenario is we will be able to do

B4X:
Object.Example(x=10) 'the rest are defaulted
Maybe in this case it would be better to have multiple signatures for the same sub like in other languages
 
Top