The 3 dots Sub querry
Posted
#1
(In Topic #516)
Guru

Can anybody tell me what the 3 dots do as the help example is not very helpful! The text below is taken from here.
<HR>[hr][/hr]</HR>
Passing extra arguments to another function
SINCE 3.6
The … keyword can be used to transmit the extra arguments to another function accepting them.
Example
Posted
Guru

I find a lot of that in Gambas help.
The help text seems to say nothing more than what is obvious.
Like Control.Public (sets control to Public) aaah i see, I'd have never guessed
(I actually edited that wiki page to be a bit more descriptive)
Posted
Regular

cogier said
Hi,
Can anybody tell me what the 3 dots do as the help example is not very helpful! …
Here is a simple example…
…but I'll try to think of a better one after lunch.
Posted
Regular

Where 3dot variable is now type boolean.
…still not a great example, but does this help?
Posted
Regular

In this example, the functions ThreeMoreDots & LoadData can cope with a variable bunch of data. Obviously the Button function in this case is only creating 10 data variables.
Code (gambas)
I can't see any other way of referencing the … data other than using it as an argument to a Sub/Function (hence the LoadData function above).
It would be very nice if:-
Code (gambas)
The … in Gambas is basically an implementation of "variadic" function that you will find in other languages (Variadic function - Wikipedia)
Its seems to be generally regarded as a bad idea! This is mainly because the data presented to the method may not be the correct type.
Posted
Guru

Thanks for the code and explanation, I can see why you say it's a bad idea you could end up with any old data being passed! Code can often be hard to read but this would just add even more confusion.
I can't see why anybody would want to use it, unless someone has a good reason for it that I can't see….?
(I deleted you duplications)
Posted
Regular

Take a look at this Basic implementation: Variadic function - Rosetta Code
Posted
Guru

It looks to me just like a way of saving writing extra unneeded code when you want to pass a load of arguments through one function to another but not really need them in the first function.
If you consider this example…
as the form loads it calls Test() with a load of arguments.
The Test() function only wants the sName argument and it then calls PrintTest() that does want all the args.
Code (gambas)
So there the function Test()
I have not needed to use
and pass all the arguments that PrintTest() wants but Test() does not , the … takes care of it.
As for variable types and using an unknown count of args i guess that's up to the programmer. If you was not using the … method but filling in the fields like in the lower example then your types would be known and taken care off. and for unknown quantities you would use an array[]
Posted
Guru

cogier said
Hi,
Can anybody tell me what the 3 dots do as the help example is not very helpful!
You were right about the info not being helpful
I found it a bit confusing too.
I thought it needed an update to be clearer.
Now it reads more like this.
Passing extra arguments to another function
Since 3.6
If you pass a number of arguments to function1() and it then passes them to Function2() but does not use them.
The … keyword can be used to transmit the extra arguments to the function accepting them.
Example
Code (gambas)
- ProcessSomething("warning", "format description", "info")
- ' Do something with sType
- PrintMessage(sType, ...)
- ' Do some stuff with the arguments passed.
Posted
Guru

stevedee said
I can't see any other way of referencing the … data other than using it as an argument to a Sub/Function (hence the LoadData function above).
It would be very nice if:-worked, but it doesn't.Code (gambas)
The … in Gambas is basically an implementation of "variadic" function that you will find in other languages (Variadic function - Wikipedia)
Its seems to be generally regarded as a bad idea! This is mainly because the data presented to the method may not be the correct type.
I don't think it's been designed like that.
It's not something you can address or access in any way it's just a keyword to pass arguments through to another function.
(like the LoadData function).
Cant see how you'd do it in gambas with the way it already uses dots for oop
I tried checking […].Count but it says "unexpected …"
….Count is a no no too.
Handy though.
I've passed many an argument through to another that i didn't need to, will keep … in mind
Posted
Guru

Param class
/comp/gb/param - Gambas Documentation
Param.Count
Param.All
this deals with the … arguments lol.
Better adjust the wiki again.
:roll:
Posted
Guru

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?
/lang/methoddecl - Gambas Documentation
Posted
Regular

BruceSteers said
…Do you think the wiki explains it better now?
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:-
Example 1: Variadic Function
Code (gambas)
- ProcessVariadic("warning", "format description", "info", -1)
- ' 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)
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: Variadic function - Rosetta Code {Charlie likes doing that}
_______________
Example 2: Function to Function?
Code (gambas)
- PassSomeArgs("warning", "format description", "info")
- ' Do something with sType and pass all the other args to the next function.
- PrintMessage(sType, ...)
- ' Do some stuff with the known number of arguments passed.
…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
Posted
Guru

stevedee said
BruceSteers said
…Do you think the wiki explains it better now?
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:-
Example 1: Variadic FunctionCode (gambas)
ProcessVariadic("warning", "format description", "info", -1) ' 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)
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: Variadic function - Rosetta Code {Charlie likes doing that}
_______________
Example 2: Function to Function?Code (gambas)
PassSomeArgs("warning", "format description", "info") ' Do something with sType and pass all the other args to the next function. PrintMessage(sType, ...) ' Do some stuff with the known number of arguments passed.
…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
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.
It saves typing the following…
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.
Posted
Regular

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
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
[ FAST [ UNSAFE] ] [ STATIC ] \{ PUBLIC | PRIVATE } \{ PROCEDURE | SUB }
Identifier
(
[ [ BYREF ] Parameter AS Datatype [ , … ] ] [ , ]
[ OPTIONAL [ BYREF ] Optional Parameter AS Datatype [ , … ] ] [ , ] [ ... ]
)
...
ENDI think its a mess and needs a "not recommended for use" warning.
Posted
Guru

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.
I'd call it Pass Some Args. like the function name.
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.
When do you need to deal with an unknown quantity of arguments or characters?
myUnknownQuantityOfArgs=Args.All.Copy ? for one.
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?
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.
I think it just needs clarity, I've done the best i can with my knowledge.
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
Posted
Guru

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.
Posted
Regular

BruceSteers said
…I think it just needs clarity, I've done the best i can with my knowledge…
Bruce, you are doing a great job!
…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!
1 guest and 0 members have just viewed this.


