How should optional input parameters be handled for procedures. The example has three optional inputs
vars:=[x,y] , clr:="b" and prnt:="y" . if one wants to change prnt to"n", vars and clr values must be entered.
{vars:=[x,y] } , { clr:="b" } and{ prnt:="y"} this is a good method because one just enteres prnt="n". But have to remember the input parameter name prnt.
I have a 3rd option, but it is to complicated and probably unreliable to use in practice. and with more than 3 optional inputs too difficult to code.
I am wondering are the other approaches and what is the prefered methodology. I have about 30+ procedures to apply this to in a package.
Edit:- I can change the prnt to boolean true, false instead of "y" , "n". That would make the all the optional inputs different types.
In Test1 its should be vars::list:=[x,y] not vars::{list , `string`}:=[x,y]



|
(1) |



![Test1 := proc (A, B, vars::{list, string} := [x, y], clr::string := Geomclr, prnt::string := "y") if vars::string then clr := vars; vars := [x, y] end if; if clr = "y" or clr = "n" then prnt := clr; clr := Geomclr end if; print(clr); if prnt = "y" then print("good") end if; A*vars[1]+B*vars[2] end proc](/ViewTemp.ashx?f=157736_1708868808/13077c86ec9a532120426e1ad3d36a8d.gif)



|
(2) |
![Test1(A, B, [r, s], "n")](/ViewTemp.ashx?f=157736_1708868808/1e90691d395437039c1f48a078f9b682.gif)


![Test1(A, B, [x, y], "b", "n")](/ViewTemp.ashx?f=157736_1708868808/f39d12cba0ad8c0ccf0f1c4e21d1dad4.gif)

|
(3) |




![Test2 := proc (A, B, { vars::{list} := [x, y], clr::string := Geomclr, prnt::string := "y" }) print(clr); if prnt = "y" then print("good") end if; A*vars[1]+A*vars[2] end proc](/ViewTemp.ashx?f=157736_1708868808/85e84fa3396add0b24d765659c636c30.gif)




|
(4) |


|
(5) |


|
(6) |


|
(7) |
![Test2(A, B, prnt = "n", clr = "green", l = [r, s])](/ViewTemp.ashx?f=157736_1708868808/0eb8436d3ff3824d42cfe470eeec0aec.gif)

|
(8) |

# 3 This is possible but is a very complicated method of handling the optional inputs and difficult the handle altered sequence on inputs.

![Test3 := proc (A, B, vars::{list, string} := [x, y], clr::string := Geomclr, prnt::string := "y") local varsl, clrl, prntl; global Geomclr; varsl := vars; clrl := clr; prntl := prnt; if vars::string then varsl := [x, y]; if vars = "y" or vars = "n" then prntl := vars; clrl := Geomclr elif vars = "r" or vars = "g" or vars = "b" then clrl := vars end if elif vars::list and clr = "y" or clr = "n" then prntl := clr; clrl := Geomclr end if; if clr = "y" or clr = "n" and vars::string then prntl := clr; clrl := vars end if; print("Colour print out ", clrl); if prntl = "y" then print("This is a test Message") end if; A*varsl[1]+B*varsl[2] end proc](/ViewTemp.ashx?f=157736_1708868808/1537d56f05e236e9dc3960b0426e48b1.gif)



|
(9) |
![Test3(A, B, [r, s])](/ViewTemp.ashx?f=157736_1708868808/83f9e797952c8d2285886142773b77de.gif)

|
(10) |
![Test3(A, B, [r, s], "n")](/ViewTemp.ashx?f=157736_1708868808/22d351219bec9b4c663a570f1339a0d7.gif)

|
(11) |


|
(12) |
![Test3(A, B, [r, s], "r", "n")](/ViewTemp.ashx?f=157736_1708868808/2e594c1c2aece10f7ad08aff68f22c75.gif)

|
(13) |


|
(14) |


|
(15) |

|
Download Q_2024-02-25_Test_proc_Args.mw