Any way to make a LIST parameter optional?

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Any way to make a LIST parameter optional?

Post by jassing »

something like:

Code: Select all

Procedure fish( List test()=NewList )
EndProcedure

fish(#Null)
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: Any way to make a LIST parameter optional?

Post by AZJIO »

?

Code: Select all

Procedure fish( List test() )
	ClearList(test())
EndProcedure

Procedure fish()
	Protected NewList test()
EndProcedure
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Any way to make a LIST parameter optional?

Post by STARGÅTE »

Only if you use a helper structure:

Code: Select all

Structure MyList
	List Test.i()
EndStructure

Procedure fish( *MyList.MyList = #Null )
	If *MyList
		ProcedureReturn ListSize(*MyList\Test())
	Else
		ProcedureReturn 0
	EndIf
EndProcedure

Define MyList.MyList
AddElement(MyList\Test())

Debug fish(MyList)
Debug fish(#Null)
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
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Any way to make a LIST parameter optional?

Post by jassing »

STARGÅTE wrote: Wed May 15, 2024 1:50 pm Only if you use a helper structure:
that's how I currently do it; but it's, er, inelegant.

thanks.
-j
Post Reply