Procedure Parameters

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
akee
Enthusiast
Enthusiast
Posts: 496
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Procedure Parameters

Post by akee »

Self-explanatory. This would be so helpful in development.

Code: Select all

CountProcedureParameter()
ProcedureParameter( ByIndex )
ProcedureParameter( ByName$ )
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Procedure Parameters

Post by jacdelad »

What would be the advantage?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Quin
Addict
Addict
Posts: 1131
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Procedure Parameters

Post by Quin »

Yeah, PB (very unfortunately) doesn't have varargs or anything similar, so what would the use case for this be?
akee
Enthusiast
Enthusiast
Posts: 496
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Procedure Parameters

Post by akee »

jacdelad wrote: Tue Jan 09, 2024 3:56 pm What would be the advantage?
:shock:


This would be one.

https://www.purebasic.fr/english/viewtopic.php?t=83339
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Procedure Parameters

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Procedure Parameters

Post 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.
bye,
Daniel
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Procedure Parameters

Post by juergenkulow »

Would you like to have a variable argument list like in C?
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Procedure Parameters

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Procedure Parameters

Post 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.
akee wrote: Tue Jan 23, 2024 9:10 am
jacdelad wrote: Tue Jan 09, 2024 3:56 pm What would be the advantage?
:shock:


This would be one.

https://www.purebasic.fr/english/viewtopic.php?t=83339
bye,
Daniel
akee
Enthusiast
Enthusiast
Posts: 496
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Procedure Parameters

Post by akee »

Yes, similar to this: https://cplusplus.com/reference/cstdarg/va_arg/

but in PureBasic. :o
Post Reply