Questions tagged [arguments]

An argument is a value passed to a function, procedure, or command line program. This also refers to the Array-like `arguments` object in JavaScript.

An argument is a value passed to a function, procedure, or program. It is often used interchangeably with the word "parameter", which also has more specific definitions. Usually "argument", or "actual parameter" (as opposed to "formal parameter") is the value of the parameter used within the called routine.

In other words, parameters are used in procedure definitions, and arguments are used in procedure calls.

arguments can also refer to the Array-like object in JavaScript that is available inside functions, this object can be used to access all of the function's arguments regardless of the function's signature.

11091 questions
461
votes
21 answers

How can I convert the "arguments" object to an array in JavaScript?

The arguments object in JavaScript is an odd wart—it acts just like an array in most situations, but it's not actually an array object. Since it's really something else entirely, it doesn't have the useful functions from Array.prototype like…
Andrew Coleson
  • 10,100
  • 8
  • 32
  • 30
414
votes
7 answers

How do I define a function with optional arguments?

I have a Python function which takes several arguments. Some of these arguments could be omitted in some scenarios. def some_function (self, a, b, c, d = None, e = None, f = None, g = None, h = None): #code The arguments d through h are strings…
Thalia
  • 13,637
  • 22
  • 96
  • 190
405
votes
6 answers

docker build with --build-arg with multiple arguments

According to the documentation, it's possible to define multiple args for the flag --build-arg, but I can't find out how. I tried the following: docker build -t essearch/ess-elasticsearch:1.7.6 --build-arg number_of_shards=5 number_of_replicas=2…
Emilien Brigand
  • 9,943
  • 8
  • 32
  • 37
386
votes
5 answers

How to add reference to a method parameter in javadoc?

Is there a way to add references to one or more of a method's parameters from the method documentation body? Something like: /** * When {@paramref a} is null, we rely on b for the discombobulation. * * @param a this is one of the parameters *…
ripper234
  • 222,824
  • 274
  • 634
  • 905
383
votes
13 answers

How can I print multiple things (fixed text and/or variable values) on the same line, all at once?

I have some code like: score = 100 name = 'Alice' print('Total score for %s is %s', name, score) I want it to print out Total score for Alice is 100, but instead I get Total score for %s is %s Alice 100. How can I get everything to print in the…
user1985351
  • 4,589
  • 6
  • 22
  • 25
375
votes
8 answers

Setting default value for TypeScript object passed as argument

function sayName(params: {firstName: string; lastName?: string}) { params.lastName = params.lastName || 'smith'; // <<-- any better alternative to this? var name = params.firstName + params.lastName alert(name); } sayName({firstName:…
AJP
  • 26,547
  • 23
  • 88
  • 127
360
votes
23 answers

C default arguments

Is there a way to specify default arguments to a function in C?
Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94
347
votes
2 answers

What is $@ in Bash?

I reckon that the handle $@ in a shell script is an array of all arguments given to the script. Is this true? I ask because I normally use search engines to gather information, but I can't google for $@ and I have grown too accustomed to easily…
vecvan
  • 3,479
  • 2
  • 15
  • 3
330
votes
10 answers

Normal arguments vs. keyword arguments

How are "keyword arguments" different from regular arguments? Can't all arguments be passed as name=value instead of using positional syntax?
mk12
  • 25,873
  • 32
  • 98
  • 137
329
votes
29 answers

Getting the last argument passed to a shell script

$1 is the first argument. $@ is all of them. How can I find the last argument passed to a shell script?
Thomas
  • 10,358
  • 4
  • 27
  • 35
324
votes
3 answers

if arguments is equal to this string, define a variable like this string

I am doing some bash script and now I got one variable call source and one array called samples, like this: source='country' samples=(US Canada Mexico...) as I want to expand the number of sources (and each source has its own samples) I tried to…
Alejandro
  • 4,945
  • 6
  • 32
  • 30
294
votes
13 answers

find: missing argument to -exec

I was helped out today with a command, but it doesn't seem to be working. This is the command: find /home/me/download/ -type f -name "*.rm" -exec ffmpeg -i {} -sameq {}.mp3 && rm {}\; The shell returns find: missing argument to `-exec' What I am…
Abs
  • 56,052
  • 101
  • 275
  • 409
294
votes
6 answers

Meaning of "[: too many arguments" error from if [] (square brackets)

I couldn't find any one simple straightforward resource spelling out the meaning of and fix for the following BASH shell error, so I'm posting what I found after researching it. The error: -bash: [: too many arguments Google-friendly version: bash…
user56reinstatemonica8
  • 32,576
  • 21
  • 101
  • 125
283
votes
4 answers

Is there a difference between foo(void) and foo() in C++ or C?

Consider these two function definitions: void foo() { } void foo(void) { } Is there any difference between these two? If not, why is the void argument there? Aesthetic reasons?
Landon
  • 15,166
  • 12
  • 37
  • 30
270
votes
5 answers

Converting an array to a function arguments list

Is it possible to convert an array in JavaScript into a function argument sequence? Example: run({ "render": [ 10, 20, 200, 200 ] }); function run(calls) { var app = .... // app is retrieved from storage for (func in calls) { // What should…
dpq
  • 9,028
  • 10
  • 49
  • 69