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
10
votes
1 answer

Using the Poco C++ Library, how can I pass data to a thread?

So my question actually has several parts: Using the Poco Threading Library: What are all of the possible methods for passing data to threads (at both thread invocation and for an already running thread). Which methods are preferred by you and why?…
Homer6
  • 15,034
  • 11
  • 61
  • 81
10
votes
3 answers

Ruby: Automatically set instance variable as method argument?

Are there any plans to implement ruby behavior similar to the CoffeeScript feature of specifying an instance variable name in a method argument list? Like class User def initialize(@name, age) # @name is set implicitly, but @age isn't. #…
Kelvin
  • 20,119
  • 3
  • 60
  • 68
9
votes
4 answers

How to declare two functions taking each other's signature as argument?

Is it possible to emulate something like this: typedef boost::function B; typedef boost::function A; The main goal is to be able to write code like this (in pseudo-c++): void a_(B b) { // ... b(a_); } void b_(A a) { // ... …
abyss.7
  • 13,882
  • 11
  • 56
  • 100
9
votes
1 answer

How to pass a function and its arguments through a wrapper function in R? Similar to *args and *kwargs in python

I want to write a wrapper function in R. I should take a function and its arguments. Do something, and then call the function with the supplied arguments. I know how to do it in python, but I search for an implementation in R. In python I would…
Nico
  • 197
  • 2
  • 6
9
votes
3 answers

Should I pass a jQuery or DOM object as arguments? (Performance Question)

Which is better performance wise. foo(this); function foo(element) { $(element).index(); } Or should I do foo($(this)); function foo($element) { $element.index(); } Obviously taking into account that I will be using the argument a…
9
votes
6 answers

Javascript Find argument passed to a function

I am needing to find the argument passed to a function from the function. Let us suppose I have a function called foo: function foo() { var a = 3; var b = "hello"; var c = [0,4]; bar(a - b / c); bar(c * a + b); } function bar(arg) {…
Peter Olson
  • 139,199
  • 49
  • 202
  • 242
9
votes
1 answer

Functional-style JavaScript: good practice to avoid argument mutation?

This is a rather general question. Functional-style programming promotes the idea that a program is about transforming data through functions, and that mutation should be avoided (except possibly within a function, seen as a basic unit of…
9
votes
6 answers

PowerShell Splatting the Argumentlist on Invoke-Command

How is it possible to use the parameters collected in a hash table for use with ArgumentList on Invoke-Command? $CopyParams = @{ Source = 'E:\DEPARTMENTS\CBR\SHARE\Target' Destination = 'E:\DEPARTMENTS\CBR\SHARE\Target 2' Structure …
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
9
votes
7 answers

Difference of function argument as (const int &) and (int & a) in C++

I know that if you write void function_name(int& a), then function will not do local copy of your variable passed as argument. Also have met in literature that you should write void function_name(const int & a) in order to say compiler, that I dont…
Narek
  • 38,779
  • 79
  • 233
  • 389
9
votes
2 answers

Python argparse treat arguments in different ways

I want to create an optional argument, which will be the '-- ' (double dash and a space) and get everything after it as its value. The problem is that some other optional arguments might appear after '-- '. I don't want these to be parsed as…
9
votes
3 answers

Parsing/passing command line arguments to a bash script - what is the difference between "$@" and "$*"?

I am using a bash script to call and execute a .jar file from any location without having to constantly enter its explicit path. The .jar requires additional variable parameters to be specified at execution, and as these can be anything, they cannot…
9
votes
1 answer

Replace the argument with a list in R

Some times there is a function which has an arbitrary number of arguments. For example, the bootstrapPage function of package shiny. If I have a data.frame and I want to create one widget for one row, then I have not figured out a pretty way to pass…
wush978
  • 3,114
  • 2
  • 19
  • 23
9
votes
3 answers

storing passed arguments in separate variables -shell scripting

In my script "script.sh" , I want to store 1st and 2nd argument to some variable and then store the rest to another separate variable. What command I must use to implement this task? Note that the number of arguments that is passed to a script will…
Nathan Pk
  • 709
  • 4
  • 18
  • 27
9
votes
2 answers

Arguments with Powershell Scripts on Launch

Like in C and other languages, you can give to the script/.exe arguments when you physically execute the script. For example: myScript.exe Hello 10 P Whereby Hello, 10 and P are passed to some variable in the program itself. Is this possible in…
PnP
  • 3,133
  • 17
  • 62
  • 95
9
votes
4 answers

Using command-line argument for passing files to a program

How can I receive a file as a command-line argument?
Johanna
  • 27,036
  • 42
  • 89
  • 117