Page 1 of 1
Procedure Parameters
Posted: Tue Jan 09, 2024 3:29 pm
by akee
Self-explanatory. This would be so helpful in development.
Code: Select all
CountProcedureParameter()
ProcedureParameter( ByIndex )
ProcedureParameter( ByName$ )
Re: Procedure Parameters
Posted: Tue Jan 09, 2024 3:56 pm
by jacdelad
What would be the advantage?
Re: Procedure Parameters
Posted: Tue Jan 09, 2024 4:27 pm
by Quin
Yeah, PB (very unfortunately) doesn't have varargs or anything similar, so what would the use case for this be?
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 9:10 am
by akee
jacdelad wrote: Tue Jan 09, 2024 3:56 pm
What would be the advantage?
This would be one.
https://www.purebasic.fr/english/viewtopic.php?t=83339
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 10:04 am
by STARGÅTE
akee wrote: Tue Jan 09, 2024 3:29 pm
Self-explanatory. This would be so helpful in development.
Code: Select all
CountProcedureParameter()
ProcedureParameter( ByIndex )
ProcedureParameter( ByName$ )
Not really "Self-explanatory". Are these function compiler functions like SizeOf() or Defined() or runtime functions?
If CountProcedureParameter() is a compiler function, it whould return always the number of parameters defined in the procedure definition (with all additional optional arguments). However, if CountProcedureParameter() would be a runtime function, it would also give the number of all arguments, because in PureBasic there is no difference if an optional argument is passed or not.
Code: Select all
Procedure Test(A.i, B.i=-1)
ProcedureReturn CountProcedureParameter()
EndProcedure
Debug Test(7, 8) ; Would return 2, because two parameter are passed.
Debug Test(7) ; Would return 2 as well, because this line is called as Test(2, -1)
Debug Test(7, 8, 9) ; Would raise an error, because not all arguments are defined.
Even, if the compiler would ignore such limitation, how the compiler should know the argument type (integer, double, string) and handle the return type of ProcedureParameter(ByIndex) or ProcedureParameter(ByName$)?
In the core of PureBasic, such a wish cannot be fulfilled.
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 12:38 pm
by DarkDragon
I guess he/she/they/... just wants varargs and showed one solution how it could look like, not explicitly wanting exactly these functions. That's at least what I guess from his/her/their/... last post here.
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 1:02 pm
by juergenkulow
Would you like to have a
variable argument list like in C?
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 1:16 pm
by STARGÅTE
From the author's title and article it is not obvious that he wants procedures with arbitrary number of arguments.
I thought, ProcedureParameter() is similar to GetRuntimeInteger() or GetRuntimeString() from the Runtime library, just for procedure's arguments.
Re: Procedure Parameters
Posted: Tue Jan 23, 2024 4:31 pm
by DarkDragon
STARGÅTE wrote: Tue Jan 23, 2024 1:16 pm
From the author's title and article it is not obvious that he wants procedures with arbitrary number of arguments.
I thought, ProcedureParameter() is similar to GetRuntimeInteger() or GetRuntimeString() from the Runtime library, just for procedure's arguments.
Indeed, it wasn't clear to me either, until we got this, because it essentially ignores all the other information he/she/they/... got by all previous posts and points to the use case of variadic arguments.
Re: Procedure Parameters
Posted: Wed Jan 24, 2024 8:54 am
by akee