# Passing optional parameters to functions

Assume I want to write a function which has to have an argument structure like

myFunction[variable_,parameters_]


for compatibility reasons. Where parameters should contain a variable number of parameters (myFunction has just two parameters however). I have been using rules lists to functions to solve this:

variable=0
parameters={param1->1,param2->2}
myFunction[variable,parameters]


which I accessed inside the Module as param1 /. parameters, etc.

Now I am reading that this kind of substitution is disfavored for efficiency reasons and that it is better to use With or Block to insert values.

So what is the recommended way to pass to and substitute in functions with given argument number multiple parameters? As an extra: Is there a way to do it which is compatible with Compile?

-
Your question is well-covered in the Mathematica documentation. What you call parameters are called options in Mathematica, so search on options. Also, passing options as rules is not "disfavored"; it is the standard way to do it. –  m_goldberg Mar 24 at 14:22
Well, searching for options does return a plethora of results indeed;) I didn't say that passing options is disfavored. What I wanted to say is that inserting numerical parameter values by substitution with ./ is said to be less efficient than using With or Block in the documentation. I wonder how I can take this into account when passing arguments. If you point me to the relevant part of the documentation I shall be glad. –  highsciguy Mar 24 at 14:33
@highsciguy Try looking for the solution in function-construction –  Kuba Mar 24 at 19:25