Doh! we all missed it.
Param class
http://gambaswiki.org/wiki/comp/gb/param
Param.Count
Param.All
this deals with the ... arguments lol.
Better adjust the wiki again.
The 3 dots Sub querry
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: The 3 dots Sub querry
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: The 3 dots Sub querry
I've updated the wiki again.
I think the main problem for us was the info about using Param.class was shown before the previous example and not in the bit about using ... so we all missed it :-\
Do you think the wiki explains it better now?
http://gambaswiki.org/wiki/lang/methoddecl
I think the main problem for us was the info about using Param.class was shown before the previous example and not in the bit about using ... so we all missed it :-\
Do you think the wiki explains it better now?
http://gambaswiki.org/wiki/lang/methoddecl
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: The 3 dots Sub querry
I need some 'quality thinking time' to do this justice, which I don't have right now. But my initial reaction would be to show 2 examples rather than lumping it all together:-BruceSteers wrote: ↑Thursday 17th December 2020 2:58pm ...Do you think the wiki explains it better now?
Example 1: Variadic Function
Sub Main()
ProcessVariadic("warning", "format description", "info", -1)
End
Sub ProcessVariadic(...)
' Here we use the Param class to access and print all arguments supplied via "..." (you must take care of variable types if they are unknown)
Print "There are " & Param.Count & " arguments"
Dim iType As Integer
For Each vVar As Variant In Param.All
iType = TypeOf(vVar)
If iType = gb.String Then
Print "Arg is a String: " & vVar
Else If iType = gb.Integer Then
Print "Arg is Integer: " & Str(vVar)
Endif
Next
End
I'd probably replace the If...then...else block in the above with Select Case as there are several data types that require filtering.A cleaned-up version could also be posted on the Rosetta Code wiki: https://rosettacode.org/wiki/Variadic_function {Charlie likes doing that}
_______________
Example 2: Function to Function?
Sub Main()
PassSomeArgs("warning", "format description", "info")
End
Sub PassSomeArgs(sType As String, ...)
' Do something with sType and pass all the other args to the next function.
Print "Got message type " & sType
PrintMessage(sType, ...)
End
Sub PrintMessage(sType As String, sFormat As String, sInfo As String)
' Do some stuff with the known number of arguments passed.
End
...but I've lost-the-plot with this example, so this is where I need some time to give it more thought.I hope this is of some help Bruce
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: The 3 dots Sub querry
the PassSomeArgs() function shows how to use ... to simply pass arguments through one function to another, no need to use Param that way as you know the amount of args and types.stevedee wrote: ↑Thursday 17th December 2020 8:43pmI need some 'quality thinking time' to do this justice, which I don't have right now. But my initial reaction would be to show 2 examples rather than lumping it all together:-BruceSteers wrote: ↑Thursday 17th December 2020 2:58pm ...Do you think the wiki explains it better now?
Example 1: Variadic Function
I'd probably replace the If...then...else block in the above with Select Case as there are several data types that require filtering.
Sub Main() ProcessVariadic("warning", "format description", "info", -1) End Sub ProcessVariadic(...) ' Here we use the Param class to access and print all arguments supplied via "..." (you must take care of variable types if they are unknown) Print "There are " & Param.Count & " arguments" Dim iType As Integer For Each vVar As Variant In Param.All iType = TypeOf(vVar) If iType = gb.String Then Print "Arg is a String: " & vVar Else If iType = gb.Integer Then Print "Arg is Integer: " & Str(vVar) Endif Next End
A cleaned-up version could also be posted on the Rosetta Code wiki: https://rosettacode.org/wiki/Variadic_function {Charlie likes doing that}
_______________
Example 2: Function to Function?
...but I've lost-the-plot with this example, so this is where I need some time to give it more thought.
Sub Main() PassSomeArgs("warning", "format description", "info") End Sub PassSomeArgs(sType As String, ...) ' Do something with sType and pass all the other args to the next function. Print "Got message type " & sType PrintMessage(sType, ...) End Sub PrintMessage(sType As String, sFormat As String, sInfo As String) ' Do some stuff with the known number of arguments passed. End
I hope this is of some help Bruce
It saves typing the following...
Sub PassSomeArgs(sType As String, sFormat As String, sInfo As String)
Print "Got message type " & sType
PrintMessage(sType, sFormat, sInfo)
End
As sFormat and sInfo are not used in the PassSomeArgs() function it shows the additional args can be passed through using ...I was trying to keep the examples simple as it's already quite big on the page wasn't looking to show how to handle every variable type, just a simple example showing the basics, which is more than it did do..
I might make a more detailed example in a separate page and link to it instead.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: The 3 dots Sub querry
Well, I can't see the point of the 2nd example (Function to Function, or whatever you want to call it).
If you need to know what the datatype is that's passed by "..." to the second function, whats the point?
Seems to me that you could replace the 2 functions with one function.
When do you need to deal with an unknown quantity of arguments or characters?
When you open a string file, there are methods to deal with any length of the string.
When you grab stuff from a website, you can use a Collection (or a JSONCollection) to handle the data.
Also, why does my Message example work when there is no mention in Help that it should?
There also seems to be confusion with the use of "..." in Help files. Here is one example:-
I think [, ...] just means 'and so on'
In fact if you look closely at "methoddecl" you will see two versions of 3 dots.
I think its a mess and needs a "not recommended for use" warning.
If you need to know what the datatype is that's passed by "..." to the second function, whats the point?
Seems to me that you could replace the 2 functions with one function.
When do you need to deal with an unknown quantity of arguments or characters?
When you open a string file, there are methods to deal with any length of the string.
When you grab stuff from a website, you can use a Collection (or a JSONCollection) to handle the data.
Also, why does my Message example work when there is no mention in Help that it should?
There also seems to be confusion with the use of "..." in Help files. Here is one example:-
Code: Select all
Value = Choose ( Choice , Result1 , Result2 [ , ... ] )
I think [, ...] just means 'and so on'
In fact if you look closely at "methoddecl" you will see two versions of 3 dots.
Code: Select all
[ FAST [ UNSAFE] ] [ STATIC ] { PUBLIC | PRIVATE } { PROCEDURE | SUB }
Identifier
(
[ [ BYREF ] Parameter AS Datatype [ , … ] ] [ , ]
[ OPTIONAL [ BYREF ] Optional Parameter AS Datatype [ , … ] ] [ , ] [ ... ]
)
...
END
I think its a mess and needs a "not recommended for use" warning.
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: The 3 dots Sub querry
I'd call it Pass Some Args. like the function name.Well, I can't see the point of the 2nd example (Function to Function, or whatever you want to call it).
If you need to know what the datatype is that's passed by "..." to the second function, whats the point?
Seems to me that you could replace the 2 functions with one function.
It's more about saving writing code, yes the 2 functions could be one but what if the code was far more complex and it was simpler to do it that way. perhaps you have a bunch of args to pass to a couple of functions but don't want to set global variables.
Maybe the use of it that way does not suit your coding style but it may suit someone else.
myUnknownQuantityOfArgs=Args.All.Copy ? for one.When do you need to deal with an unknown quantity of arguments or characters?
err I have no idea what this refers to.Also, why does my Message example work when there is no mention in Help that it should?
I think it just needs clarity, I've done the best i can with my knowledge.There also seems to be confusion with the use of "..." in Help files. Here is one example:-
Code: Select all
Value = Choose ( Choice , Result1 , Result2 [ , ... ] )
I think [, ...] just means 'and so on'
In fact if you look closely at "methoddecl" you will see two versions of 3 dots.
Code: Select all
[ FAST [ UNSAFE] ] [ STATIC ] { PUBLIC | PRIVATE } { PROCEDURE | SUB }
Identifier
(
[ [ BYREF ] Parameter AS Datatype [ , … ] ] [ , ]
[ OPTIONAL [ BYREF ] Optional Parameter AS Datatype [ , … ] ] [ , ] [ ... ]
)
...
END
I think its a mess and needs a "not recommended for use" warning.
But i can see many uses for the function if understood better how it all works.
The wiki last week was rubbish and showed nothing. We all missed the bit about using Param.class as the info was misplaced on the page.
It's not perfect and it's not handling every possible thing as it's a simple example on a help page.
I think it's clearer and covering the bases better now though even if you don't see the point in using it that way , can you see it can be used that way?
You're right about the possible confusion between the actual use of ... keyword and ... meaning and so on.
Probably won't matter as it's only on that page where Param and ... are a keyword. I'm sure most will twig the difference.
Bruce
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: The 3 dots Sub querry
Essentially the ... keyword seems a waste of time if you consider the alternatives, a simple Array[]
you could use
MyFunction(...)
' use Param to get all args if any.
End
Or you could use
MyFunction(Optional MyArgs As Variant[])
' Use the array.
End
But it's there . and it will suit the coding style of some.
you could use
MyFunction(...)
' use Param to get all args if any.
End
Or you could use
MyFunction(Optional MyArgs As Variant[])
' Use the array.
End
But it's there . and it will suit the coding style of some.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: The 3 dots Sub querry
Bruce, you are doing a great job!BruceSteers wrote: ↑Friday 18th December 2020 8:17pm ...I think it just needs clarity, I've done the best i can with my knowledge...
...but you did ask for input. My opinion is just that...my opinion.
Its up to you (as you have taken on this task) to apply a garbage filter and use what you think is appropriate.
In my view, the Help system for Microsoft Visual Basic 6 (Not .NET) is the Gold Standard. Just about everything in the language is covered with a description of the syntax followed by at least one, and often more than one example. I just couldn't believe how clearly everything about VB.Classic was laid out, having spent a few years previously working with Borlands Turbo Pascal.
Gambas was created to be the Visual Basic language for Linux, so it has always frustrated me that Gambas Help is not a patch on VB Help. The original disconnect between Methoddecl and the Param class is just one example. But there are probably many more where cross-referencing would be helpful, maybe even essential.
I think Gambas could of had a much larger user base if the documentation had been sorted out 10 years ago.
...but hey! that's just my opinion!