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.

777 questions
641
votes
13 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
  • 7,195
  • 7
  • 24
  • 25
470
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,478
  • 6
  • 29
  • 41
105
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…
85
votes
8 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,477
  • 5
  • 30
  • 45
63
votes
7 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
  • 631
  • 1
  • 6
  • 3
59
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
  • 57,710
  • 92
  • 283
  • 453
58
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,631
  • 6
  • 46
  • 75
51
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,558
  • 4
  • 16
  • 22
48
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,991
  • 3
  • 22
  • 43
40
votes
6 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
  • 14,202
  • 10
  • 68
  • 91
36
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,811
  • 6
  • 47
  • 74
30
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
  • 6,747
  • 16
  • 85
  • 143
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
  • 68,213
  • 24
  • 160
  • 246
29
votes
4 answers

Remove last argument from argument list of shell script (bash)

This question concerns a bash script that is run in automator osx. I am using automator actions to get and filter a bunch of file references from the finder. Then I append to that list the name of the parent folder, also via an automator action.…
Nordanfors
  • 371
  • 1
  • 4
  • 9
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
  • 266,786
  • 75
  • 396
  • 414
1
2 3
51 52