2023-02-13 03:38:29 +00:00
|
|
|
Option _Explicit
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
DEFLNG A-Z
|
|
|
|
$Console:Only
|
2023-02-13 03:38:29 +00:00
|
|
|
Dim Debug As Long
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
Debug = -1
|
|
|
|
|
|
|
|
'$include:'../../../source/global/constants.bas'
|
2024-01-06 04:01:51 +00:00
|
|
|
'$include:'../../../source/utilities/type.bi'
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
sp = "@" ' Makes the output readable
|
|
|
|
|
|
|
|
Type TestCase
|
|
|
|
args As String
|
|
|
|
results As String
|
|
|
|
End Type
|
|
|
|
|
|
|
|
Dim tests(6) As TestCase
|
|
|
|
|
|
|
|
tests(1).args = "2"
|
|
|
|
tests(1).results = MKL$(-1) + MKL$(0) + MKL$(0) + MKL$(0)
|
|
|
|
|
|
|
|
tests(2).args = "2" + sp + "," + sp + "3"
|
|
|
|
tests(2).results = MKL$(-1) + MKL$(-1) + MKL$(0) + MKL$(0)
|
|
|
|
|
|
|
|
' (2, foo(3, 2) ) - includes two function arguments, with one of them being a function call
|
|
|
|
tests(3).args = "2" + sp + "," + sp + _
|
|
|
|
"foo" + sp + "(" + sp + "3" + sp + "," + sp + "2" + sp + ")"
|
|
|
|
tests(3).results = MKL$(-1) + MKL$(-1) + MKL$(0) + MKL$(0) + MKL$(0)
|
|
|
|
|
|
|
|
' Trailing comma at the end of argument list
|
|
|
|
tests(4).args = "2" + sp + "," + sp + "3" + sp + ","
|
|
|
|
tests(4).results = MKL$(-1) + MKL$(-1) + MKL$(0) + MKL$(0)
|
|
|
|
|
|
|
|
tests(5).args = "2" + sp + "," + sp + "," + sp + "3"
|
|
|
|
tests(5).results = MKL$(-1) + MKL$(0) + MKL$(-1) + MKL$(0)
|
|
|
|
|
|
|
|
tests(6).args = "2" + sp + "," + sp + ","
|
|
|
|
tests(6).results = MKL$(-1) + MKL$(0) + MKL$(0) + MKL$(0)
|
|
|
|
|
2023-02-13 03:38:29 +00:00
|
|
|
ReDim provided(10) As Long, i As Long
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
For i = 1 To UBOUND(tests)
|
|
|
|
argStringToArray tests(i).results, provided()
|
|
|
|
|
|
|
|
Print "Test"; i; ", Args: "; tests(i).args
|
2023-02-13 03:38:29 +00:00
|
|
|
|
|
|
|
Dim k As Long
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
For k = 1 To UBOUND(provided)
|
2023-02-13 03:38:29 +00:00
|
|
|
Dim result As Long
|
|
|
|
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
result& = hasFunctionElement(tests(i).args, k)
|
|
|
|
|
|
|
|
Print " Expected:"; provided(k); ", Actual"; result&;
|
|
|
|
If provided(k) = result& Then
|
|
|
|
Print " PASS!"
|
|
|
|
Else
|
|
|
|
Print " FAIL!"
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
|
|
|
|
Print
|
|
|
|
Next
|
|
|
|
|
|
|
|
System
|
|
|
|
|
|
|
|
'$include:'../../../source/utilities/elements.bas'
|
|
|
|
|
|
|
|
SUB argStringToArray(argString As String, provided() As Long)
|
2023-02-13 03:38:29 +00:00
|
|
|
ReDim provided(LEN(argString) / 4) As Long, i As Long
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
|
|
|
|
for i = 1 to UBOUND(provided)
|
|
|
|
provided(i) = CVL(MID$(argString, (i - 1) * 4 + 1, 4))
|
|
|
|
next
|
|
|
|
END SUB
|
|
|
|
|
|
|
|
FUNCTION argStringPrint$(argString As String)
|
2023-02-13 03:38:29 +00:00
|
|
|
Dim res As String, i As Long
|
|
|
|
|
Add support for optional function arguments
Currently functions only have very limited optional argument support,
this expands it so that we can have more complex sets of optional
arguments for functions, such as multiple arguments where not all need
to be provided. This will be used in the future for some upcoming
functionality.
Note that this does not support any generic optional argument format,
the commas always have to be provided unless an optional argument is at
the end of the parameter list. Thus, if you have a format with two
optional arguments and you want to omit the second, then you need to call
it as 'foo(2, , 3)`, rather than `foo(2, 3)`. This is important for
avoiding ambiguous situations, and is how many SUBs currently function.
The two functions that violate that requirement are INSTR() and
_INSTRREV(), which use the format `[?],?,?` and allow omitting the comma
for the first argument. This format is simply handled as a special case.
Fixes: #303
2023-02-07 05:57:10 +00:00
|
|
|
res$ = ""
|
|
|
|
|
|
|
|
res$ = STR$(CVL(MID$(argString, 1, 4)))
|
|
|
|
For i = 2 To LEN(argString) / 4
|
|
|
|
res$ = res$ + ", " + STR$(CVL(MID$(argString, (i - 1) * 4 + 1, 4)))
|
|
|
|
Next I
|
|
|
|
|
|
|
|
argStringPrint$ = res$
|
|
|
|
END FUNCTION
|