Questions tagged [parameters]

Parameters are a type of variable used in a subroutine to refer to the data provided as input to the subroutine.

A parameter is an intrinsic property of a procedure, included in its definition. For example, in many languages, a minimal procedure to add two supplied integers together and calculate the sum total would need two parameters, one for each integer. In general, a procedure may be defined with any number of parameters, or no parameters at all. If a procedure has parameters, the part of its definition that specifies the parameters is called its parameter list.

There are two ways of passing parameters to a procedure (both of them may not be available in every programming language):

  • by value: the value of a variable (or constant, etc.) is passed to the procedure and the original variable cannot be affected by the code in the procedure.
  • by reference: the reference to a variable is passed to a procedure and the variable's value can be changed in the procedure.
22681 questions
307
votes
12 answers

What does the construct x = x || y mean?

I am debugging some JavaScript and can't explain what this || does: function (title, msg) { var title = title || 'Error'; var msg = msg || 'Error on Request'; } Why is this guy using var title = title || 'ERROR'? I sometimes see it without a…
opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143
298
votes
10 answers

How can I read command line parameters from an R script?

I've got a R script for which I'd like to be able to supply several command-line parameters (rather than hardcode parameter values in the code itself). The script runs on Windows. I can't find info on how to read parameters supplied on the…
monch1962
  • 5,151
  • 5
  • 31
  • 38
284
votes
7 answers

What is the difference between named and positional parameters in Dart?

Dart supports both named optional parameters and positional optional parameters. What are the differences between the two? Also, how can you tell if an optional parameter was actually specified?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
280
votes
3 answers

What does the slash mean when help() is listing method signatures?

What does the / mean in Python 3.4's help output for range before the closing parenthesis? >>> help(range) Help on class range in module builtins: class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range object |…
Joschua
  • 5,816
  • 5
  • 33
  • 44
242
votes
10 answers

Reflection: How to Invoke Method with parameters

I am trying to invoke a method via reflection with parameters and I get: object does not match target type If I invoke a method without parameters, it works fine. Based on the following code if I call the method Test("TestNoParameters"), it works…
Ioannis
  • 2,985
  • 4
  • 25
  • 19
240
votes
9 answers

Default function arguments in Rust

Is it possible to create a function with a default argument? fn add(a: int = 1, b: int = 2) { a + b }
Jeroen
  • 15,257
  • 12
  • 59
  • 102
234
votes
14 answers

Ruby: How to turn a hash into HTTP parameters?

That is pretty easy with a plain hash like {:a => "a", :b => "b"} which would translate into "a=a&b=b" But what do you do with something more complex like {:a => "a", :b => ["c", "d", "e"]} which should translate into…
Julien Genestoux
  • 31,046
  • 20
  • 66
  • 93
233
votes
7 answers

HTTP Request in Swift with POST method

I'm trying to run a HTTP Request in Swift, to POST 2 parameters to a URL. Example: Link: www.thisismylink.com/postName.php Params: id = 13 name = Jack What is the simplest way to do that? I don't even want to read the response. I just want to send…
angeant
  • 2,785
  • 3
  • 17
  • 9
232
votes
10 answers

PHP check whether property exists in object or class

I understand PHP does not have a pure object variable, but I want to check whether a property is in the given object or class. $ob = (object) array('a' => 1, 'b' => 12); or $ob = new stdClass; $ob->a = 1; $ob->b = 2; In JS, I can write this to…
Micah
  • 4,254
  • 8
  • 30
  • 38
228
votes
34 answers

How many parameters are too many?

Routines can have parameters, that's no news. You can define as many parameters as you may need, but too many of them will make your routine difficult to understand and maintain. Of course, you could use a structured variable as a workaround:…
Auron
  • 13,626
  • 15
  • 47
  • 54
225
votes
10 answers

Passing Parameters JavaFX FXML

How can I pass parameters to a secondary window in javafx? Is there a way to communicate with the corresponding controller? For example: The user chooses a customer from a TableView and a new window is opened, showing the customer's info. Stage…
Alvaro
  • 11,797
  • 9
  • 40
  • 57
220
votes
8 answers

Append values to query string

I have set of URLs similar to the ones below in a list http://somesite.example/backup/lol.php?id=1&server=4&location=us http://somesite.example/news.php?article=1&lang=en I have managed to get the query strings using the following code: myurl =…
DriverBoy
  • 3,047
  • 3
  • 19
  • 21
212
votes
5 answers

How to use R's ellipsis feature when writing your own function?

The R language has a nifty feature for defining functions that can take a variable number of arguments. For example, the function data.frame takes any number of arguments, and each argument becomes the data for a column in the resulting data table.…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
212
votes
11 answers

In Swift how to call method with parameters on GCD main thread?

In my app I have a function that makes an NSRURLSession and sends out an NSURLRequest using sesh.dataTaskWithRequest(req, completionHandler: {(data, response, error) In the completion block for this task, I need to do some computation that adds a…
almel
  • 7,178
  • 13
  • 45
  • 58
209
votes
10 answers

What is the use of "ref" for reference-type variables in C#?

I understand that if I pass a value-type (int, struct, etc.) as a parameter (without the ref keyword), a copy of that variable is passed to the method, but if I use the ref keyword a reference to that variable is passed, not a new one. But with…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360