Tagged Questions
1
vote
1answer
44 views
Specifying Optional and Multiple Values in a Function Parameter
I would like to create a function that can accept multiple, optional, and additive values in a parameter.
For example, I want to have a class
class Pizza {
public function ...
0
votes
2answers
39 views
Ruby: specifying value of single argument on multiple argument function with default values
Coming from a python background, I'm used to running functions providing only the parameters that I need:
def f(a=1,b=2)
print a,b
f(b=3) #prints "1 3"
Ruby seems to provide the same syntax ...
0
votes
2answers
100 views
C++ Function with unlimited optional parameters and different choices of input variables
Been thinking about these questions for a while now but couldn't come up with an idea on how to do it.
Lets say I have a function like:
double sum( int param1 , double param2 , [ optional... ] )
{
...
1
vote
2answers
119 views
How are overloaded functions selected for suitability in C++?
I need some help understanding how overloaded C++ functions are selected by the compiler.
When given a function:
type func(type1 x, type2 y);
type func(type3 x, type2 y);
How does the compiler ...
0
votes
1answer
60 views
Pass an undefined variable as an optional argument to the function and let it populate it, but only if argument is present
In PHP some functions have an optional argument, which when passed is automatically populated inside the function with some value. Obviously function receives it by reference, since its value becomes ...
0
votes
2answers
102 views
Is it possible to have a variable number of parameters per function without overloading?
Is it possible to make it so that you don't have to overload a function definition 3 times if you want to be able to pass between 1 to 3 parameters into it?
For example instead of:
function(class a) ...
-5
votes
2answers
99 views
C# What happens when you pass null to an optional argument [closed]
If I have a function with an optional argument like so:
public string testFunction (string arg1 = "Adam"){
return "Hello " + arg1;
}
If I pass a null string to the function, will the function ...
1
vote
5answers
81 views
Optional parameter not working correctly
I have a method which takes last parameter optionally.
public static DataTable GetQueryResult<T>(string connectionString, string queryText, Dictionary<string, T> dicParameters = null)
...
5
votes
4answers
521 views
Does MATLAB lets you assign default value for input arguments for a function like python does?
I am working on a project and have many functions to create and they do need lots of debugging so instead of just hitting the run button i have to go to command window and give a function call.
does ...
0
votes
1answer
71 views
how to run a function with parameters
I have a function that simply validates forms (for old browsers). The function works just fine except that I have to pass the parameters every time I call this function, where in fact I already ...
2
votes
1answer
198 views
Python function optional arguments - possible to add as condition?
Is it possible, somehow, to aassign a condtional statement toan optional argument?
My initial attempts, using the following construct, have been unsuccessful:
y = {some value} if x == {someValue} ...
0
votes
2answers
621 views
Multiple optional parameters calling function
Assume that i have a function like this below
It takes 3 parameters and 2 have optional values
private void myfunc (int a, int b=2, int c=3)
{
//do some stuff here related to a,b,c
}
now i want ...
2
votes
1answer
1k views
Parameter passing in R when interior function arguments are dependent on optional parameters
I'm working in R and need to pass arguments to a function so that they can be used as arguments when calling another function within the original. In the example below you can see that I'm interested ...
0
votes
3answers
157 views
Easier way to pass optional function parameters using array
When I create a function that has optional parameters, I have to think about which one is more likely to be passed the most and that determines the order in which I specify them in the function ...
5
votes
4answers
2k views
Python: how to check whether optional function parameter is set
Is there an easy way in Python to check whether the value of an optional parameter comes from its default value, or because the user has set it explicitly at the function call?
2
votes
1answer
509 views
boost function with optional parameters
I have a map containing boost::function values, as defined below:
std::map <std::string, boost::function<std::string (std::string, int)> > handlers;
Let us say I define the following ...
5
votes
3answers
215 views
How to get the default value of an optional parameter
Probably this is a limitation of PHP, but is it possible somehow, to call a function - and enforcing the 'default' value of an optional parameter - even if in the function call, the optional parameter ...
2
votes
4answers
3k views
Do I need to pass empty parameters to a javascript function?
Say I have a function like this, which i'm calling throughout a script:
function form_senden( form_name, cnf, confirm_txt, trigger_field, ,do_check, chknfcs, allow, errorMsg ){
// do something
...
0
votes
3answers
538 views
C++: Default Arguments and Vectors
In C++, I want to have a function that takes an optional argument of type vector. If the argument is not provided, I want the variable to have size 0. I currently have
void ...
14
votes
5answers
9k views
Named parameters in javascript
I find the named parameters feature in C# quite useful in some cases.
calculateBMI(70, height: 175);
What if I want this in javascript?
What I don't want is -
myFunction({ param1 : 70, param2 ...
0
votes
1answer
777 views
LISP - cannot call function with optional parameter
I have this function in LISP with regular parameter and optional paremater n:
(defun lastplus (x &optional (n 0)) //default value for n is 0
( if (listp x) //if x is a list
(
...
1
vote
2answers
334 views
Referring to class variables as default parameters in PHP function
I would like to have a function in my class that has a default parameter so that one can omit the argument if required. I want the default to be a variable stored in my class;
Hi why is this showing ...
1
vote
2answers
192 views
Is there a way to determine which optional arguments were given in a VBA function call?
Say I have a VBA function with an optional argument. Is there a way to tell, from within that function, whether the calling code has supplied the optional argument or not?
Public Function ...
0
votes
4answers
213 views
What is the canonical way to make a function accept any permutation of its argument list?
Suppose I have
class A,B,C;
const A a_def;
const B b_def;
const C c_def;
void f(A a=a_def, B b=b_def, C c=c_def);
This does, if I want to use the default parameters, only allow me to omit either ...
0
votes
1answer
23 views
What is the proper name for the variables you pass into a function in PHP
function foo($bar,$barbar,$option="") {}
Is there a proper term for $bar etc., and/or name for optional variables?
5
votes
4answers
717 views
Assign pass to a function in Python
I have a piece of code that defines a function that takes a function as an argument, like so:
def stuff(n, f):
f(n)
Now, I want to provide some default value of f that does nothing. So I figured ...
4
votes
3answers
2k views
Is passing NULL param exactly the same as passing no param
I'm working with a function whose signature looks like this
afunc(string $p1, mixed $p2, array $p3 [, int $p4 = SOM_CONST [, string $p5 ]] )
In some cases I don't have data for the last parameter ...
3
votes
4answers
2k views
PHP Optional Parameters - specify parameter value by name?
I know it is possible to use optional arguments as follows:
function doSomething($do, $something = "something") {
}
doSomething("do");
doSomething("do", "nothing");
But suppose you have the ...
56
votes
3answers
14k views
How to create default value for function argument in Clojure
I come with this:
(defn string->integer [str & [base]]
(Integer/parseInt str (if (nil? base) 10 base)))
(string->integer "10")
(string->integer "FF" 16)
But it must be a better way to do this.
0
votes
1answer
244 views
Parser expression for comma-separated function call parameters
Im writing a parser than can parse expressions like myfunc1(), myfunc2(param1) and myfunc3(param1, param2) (with an unknown amount of parameters). Now I'm trying to get my parse expressions right. I'm ...
1
vote
4answers
551 views
How do you handle multi-argument JavaScript functions?
I have defined my JavaScript function as follows:
function printCompanyName(company1, company2, company3, company4, company5)
{
document.write("<p>" + company1 + "</p>");
...
1
vote
2answers
1k views
how to run my own jQuery function correctly?
I've got this code that's changing a picture and additional link with it.
var imgSwap(pic, link){
$("#sampleimg")
.load(function () {
$(this).hide();
...
25
votes
3answers
10k views
How would I skip optional arguments in a function call?
OK I totally forgot how to skip arguments in PHP.
Lets say I have:
checkbox_field
(
$name,
$value = '',
$checked = false,
$compare = '',
$parameter = ''
)
How would I call this function and ...
15
votes
9answers
9k views
Any way to specify optional parameter values in PHP?
Let's say I've got a PHP function foo:
function foo($firstName = 'john', $lastName = 'doe') {
echo $firstName . " " . $lastName;
}
// foo(); --> john doe
Is there any way to specify only the ...