Questions tagged [argument-passing]

Argument-passing may refer to two different things: (1) the process of providing a program being started with some initial pieces of information (the arguments) on its command line; (2) the process of providing the initial values (the arguments) for the parameters of a function when it is called.

789 questions
571
votes
11 answers

JavaScript variable number of arguments to function

Is there a way to allow "unlimited" vars for a function in JavaScript? Example: load(var1, var2, var3, var4, var5, etc...) load(var1)
Timo
  • 6,427
  • 6
  • 22
  • 25
457
votes
9 answers

Pass in an array of Deferreds to $.when()

Here's an contrived example of what's going on: http://jsfiddle.net/adamjford/YNGcm/20/ HTML: Click me!
JavaScript: function getSomeDeferredStuff() { var deferreds = []; var i = 1; for (i = 1; i <= 10; i++)…
adamjford
  • 7,241
  • 5
  • 26
  • 40
80
votes
4 answers

Argument passing strategy - environment variables vs. command line

Most of the applications we developers write need to be externally parametrized at startup. We pass file paths, pipe names, TCP/IP addresses etc. So far I've been using command line to pass these to the appplication being launched. I had to parse…
65
votes
7 answers

How to convert a command-line argument to int?

I need to get an argument and convert it to an int. Here is my code so far: #include using namespace std; int main(int argc,int argvx[]) { int i=1; int answer = 23; int temp; // decode arguments if(argc < 2) { …
nosedive25
  • 2,236
  • 4
  • 28
  • 45
54
votes
11 answers

Is there a difference between main(String args[]) and main(String[] args)?

Is there a difference between: public void main(String args[]) { ... } and public void main(String[] args) { ... } I don't believe so, but I am wondering.
Jérôme Verstrynge
  • 51,859
  • 84
  • 263
  • 429
46
votes
6 answers

Elegant way to pass multiple arguments to a function

I've got a function which looks like this: bool generate_script (bool net, bool tv, bool phone, std::string clientsID, std::string password, int index, std::string number, …
Tomasz Kasperczyk
  • 1,615
  • 2
  • 17
  • 38
42
votes
4 answers

Postgres integer arrays as parameters?

I understand that in Postgres pure, you can pass an integer array into a function but that this isn't supported in the .NET data provider Npgsql. I currently have a DbCommand into which I load a call to a stored proc, add in a parameter and execute…
Tristan Warner-Smith
  • 9,110
  • 5
  • 45
  • 74
42
votes
5 answers

Function pointer as an argument

Is it possible to pass a function pointer as an argument to a function in C? If so, how would I declare and define a function which takes a function pointer as an argument?
inquisitive
  • 1,178
  • 4
  • 13
  • 22
37
votes
6 answers

How to pass arguments to functions by the click of button in PyQt?

I want to pass the arguments to a function when I click the button. What should I add to this line button.connect(button, QtCore.SIGNAL('clicked()'), calluser(name)) so it will pass the value to the function: def calluser(name): print name def…
uahmed
  • 371
  • 1
  • 3
  • 3
37
votes
4 answers

Is there a way to use two '...' statements in a function in R?

I want to write a function that calls both plot() and legend() and it would be ideal if the user could specify a number of additional arguments that are then passed through to either plot() or legend(). I know I can achieve this for one of the two…
Henrik
  • 13,334
  • 9
  • 64
  • 89
33
votes
3 answers

Passing an instance method as argument in PHP

I would like to create a Listener class class Listener { var $listeners = array(); public function add(callable $function) { $this->listeners[] = $function; } public function fire() { foreach($this->listeners as…
Gergely Fehérvári
  • 7,405
  • 6
  • 43
  • 71
29
votes
2 answers

Is it a good idea to use a switch with fallthrough to handle default arguments in Javascript?

I have recently learned that you can use a neat switch statement with fallthrough to set default argument values in Javascript: function myFunc(arg1, arg2, arg3) { //replace unpassed arguments with their defaults: switch (arguments.length)…
hugomg
  • 63,082
  • 19
  • 144
  • 230
29
votes
10 answers

Calculate percentage Javascript

I have a question about javascript logic what I use to get percent of two inputs from my text fields. Here is my code: var pPos = $('#pointspossible').val(); var pEarned = $('#pointsgiven').val(); var perc = ((pEarned/pPos) *…
espresso_coffee
  • 5,076
  • 9
  • 53
  • 124
29
votes
1 answer

pass arguments between shell scripts but retain quotes

How do I pass all the arguments of one shell script into another? I have tried $*, but as I expected, that does not work if you have quoted arguments. Example: $ cat script1.sh #! /bin/sh ./script2.sh $* $ cat script2.sh #! /bin/sh echo $1 echo…
dogbane
  • 242,394
  • 72
  • 372
  • 395
26
votes
5 answers

Passing arguments django signals - post_save/pre_save

I am working on a notification app in Django 1.6 and I want to pass additional arguments to Django signals such as post_save. I tried to use partial from functools but no luck. from functools import partial post_save.connect( …
Mo J. Mughrabi
  • 5,969
  • 14
  • 68
  • 130
1
2 3
52 53