Questions tagged [function-parameter]

The function parameters are the variable names, listed in the definition of the function.

In many programming languages, parameters are the essence of the functions. The function parameters define the variable names, listed in the definition of the function. They are often confused with (and referred to as) function arguments, which actually are the real values that are passed to and received by the function when it is being called.

314 questions
4
votes
5 answers

passing a function as a parameter

void dispatch_for(dispatch_queue_t *queue, long number, void (* work)(long)){ int loop = number; int i; task_t *ctask; for(i = 0; i
Leanne
  • 667
  • 3
  • 11
  • 23
4
votes
1 answer

Setting local variables to a function instead of using globals optimize the function

In the documentation for the itertools module I found this comment def dotproduct(vec1, vec2): return sum(imap(operator.mul, vec1, vec2)) Note, many of the above recipes can be optimized by replacing global lookups with local variables…
joaquin
  • 82,968
  • 29
  • 138
  • 152
4
votes
6 answers

Is it bad form to have functions with a lot of parameters? What's the alternative?

I have a search function that queries the database and has ~15 optional parameters. Obviously this is not pretty and calling it is a bit of a mess. PHP does not allow overloading methods so I've just been creating huge function…
aw crud
  • 8,791
  • 19
  • 71
  • 115
4
votes
2 answers

Is it ok to use module constants as default function arguments in Python?

Basically something like this: DEFAULT_TIMEOUT = 10 # or even: from my_settings import DEFAULT_TIMEOUT def get_google(timeout=DEFAULT_TIMEOUT): return requests.get('google.com', timeout=timeout) I would assume that as long as the constant…
gmolau
  • 2,815
  • 1
  • 22
  • 45
4
votes
2 answers

Swift 3.0 range as function parameter

I'm making a function to get the specific days that falls on specific weekdays Ex. Sundays in 9.2016 = 4,11,18,25 import UIKit var daysOff = [Int]() func getNumberOfDaysInMonth (_ month : Int , _ Year : Int ,lookingFor : Int) -> (firstDay: Int ,…
Nitrousjp
  • 363
  • 4
  • 10
4
votes
2 answers

Passing a function which returns void but has integer arguments to another function as an ARGUMENT itself

I have recently started working on OpenCV using c++. I am having a problem with the following code. #include "cv.h" #include "highgui.h" int g_slider_position = 0; CvCapture* g_capture = NULL; void onTrackbarSlide(int pos) { …
Ashish Yadav
  • 1,667
  • 6
  • 20
  • 26
4
votes
2 answers

Swift: using member constant as default value for function parameter

I have a swift class, in which I am trying to pass a default value for a function parameter: class SuperDuperCoolClass : UIViewController { // declared a constant let primaryColor : UIColor = UIColor(red: 72.0/255.0, green: 86.0/255.0, blue:…
Devarshi
  • 16,440
  • 13
  • 72
  • 125
4
votes
3 answers

html sending parameters to function from id

I'm an absolute beginner and tried to find similar questions but couldn't. Apologies if this has been answered previously. In my assignment we need to create a form with 2 text fields and 1 button. The fields are for height and width and the idea is…
Amos Bordowitz
  • 474
  • 6
  • 19
3
votes
4 answers

How to take a typename as a parameter in a function? (C++)

I need to be able to pass a typename as a parameter: int X = FileRead(file, 9, char); The concept is for FileRead(std::fstream, int pos, ???) to read pos*sizeof(whatever the type is) to get the desired position. I tried…
user98188
3
votes
2 answers

TypeScript Array Union Type in function parameters

I have a union type of an Array of various specific lengths: [ number ] | [ number, number ] | [ number, number, number, number ] As you can see, there are requirements for an array with one element, two elements, or four elements. I am trying to…
3
votes
4 answers

conditional function arguments in typescript

Is it possible to have a conidial required argument type based on the first argument type: type ConditionalRequiredArg = T extends string ? P | undefined : P; function func(_arg1: string | number, _arg2: ConditionalRequiredArg)…
cyrus-d
  • 749
  • 1
  • 12
  • 29
3
votes
2 answers

How is a type that's forward declared in a function parameter list visible outside the function scope?

The following program compiles, which I find strange. void f(class s); using u = s; // ok, but why? s is a forward declaration of a class inside a function parameter list, and it seems to me it should not be visible outside the function…
cigien
  • 57,834
  • 11
  • 73
  • 112
3
votes
1 answer

What is the impact of final function parameters in Dart?

I recently found out it was possible to include final in function parameters. /// Handler for the footer leading checkbox void _onCheck(final bool value) { setState(() { _checked = value; }); } However, this feature is not documented…
Nato Boram
  • 4,083
  • 6
  • 28
  • 58
3
votes
0 answers

C function pointer declaration omitting parameters

In the code, I omitted parameters for int (*bar) and assigned &foo, which as 3 arguments, to bar. (*bar) received the numbers and gave me a return value. I thought this is ok but I've heard that this is actually UB. How does (*bar) receive the…
Austin
  • 41
  • 1
  • 4
3
votes
6 answers

C# Is it possible to abstract an orderby LINQ clause into a function parameter?

I have an ObservableCollection Bound to a WPF List View. I am looking to be able to sort the columns of the ListView control by clicking on the Column Header. To do this I am sorting the ObservableCollection and letting the binding take care of…
TK.
  • 46,577
  • 46
  • 119
  • 147