arguments

How to pass arguments to function referenced by variable

I have a function 'foo' and a variable '$foo' referencing it. function foo { param($value) $value + 5 } $foo = foo $foo I can call $foo without args, but how can I pass parameters? This does not work: $foo 5 $foo(5) Actually the goal is to write such code: function bar { param($callback) $callback 5 } bar(foo) ...

C++0x, How do I expand a tuple into variadic template function arguments?

Consider the case of a templated function with variadic template arguments: template<typename Tret, typename... T> Tret func(const T&... t); Now, I have a tuple t of values. How do I call func() using the tuple values as arguments? I've read about the bind() function object, with call() function, and also the apply() function in diffe...

Speed of code execution: ASP.NET-MVC versus PHP

I have a friendly argument going on with a co-worker about this, and my personal opinion is that a ASP.NET-MVC compiled web application would run more efficiently/faster than the same project that would be written in PHP. My friend disagrees. Unfortunately I do not have any solid data that I can use to back up my argument. (neither doe...

Please can I get a hint on where to focus... formatting help

The program is supposed to calculate the number of arguments, iterate over the list of arguments, for each argument convert the argument to an integer and copy it to an array, iterate over the elements of the array, adding the value of each one to a variable (this computes the sum of elements), and print the sum. There will not be more t...

VB.NET Invoke DLL method with ByRef Arguments

Using VB.NET, is there a way to pass a reference argument when invoking a function in a dll. Suppose I want to pass arg2 as a reference argument, how would I do that? method.Invoke(obj, New [Object]() {arg1, arg2, arg3}) In other words I want to point arg2 to something else within the invoked function. ...

What is a maximum number of arguments in a Python function?

It's somewhat common knowledge that Python functions can have a maximum of 256 arguments. What I'm curious to know is if this limit applies to *args and **kwargs when they're unrolled in the following manner: items = [1,2,3,4,5,6] def do_something(*items): pass I ask because, hypothetically, there might be cases where a list lar...

Why do I get a "Too many input arguments" error when not passing any?

I am working on some simple object-oriented code in MATLAB. I am trying to call one of my class methods with no input or output arguments in its definition. Function definition: function roll_dice Function call: obj.roll_dice; When this is executed, MATLAB says: ??? Error using ==> roll_dice Too many input arguments. Error in ==> ...

Java Command line arguments

I am trying to detect whether the 'a' was entered as the first string argument. ...

Should Java method arguments be used to return multiple values ?

Since arguments sent to a method in Java point to the original data structures in the caller method, did its designers intend for them to used for returning multiple values, as is the norm in other languages like C ? Or is this a hazardous misuse of Java's general property that variables are pointers ? ...

How can I know that PowerShell function parameter is omitted

Consider such function: function Test($foo, $bar) { ... } We can call it: Test -foo $null Test How can I know when the -foo was omitted, and when it was $null? ...

How to omit $null arguments calling a function?

Consider such function: $missed = "{716C1AD7-0DA6-45e6-854E-4B466508EB96}" function Test($foo = $missed, $bar = $missed) { if(!$foo) { throw "error" } if(!$bar) { throw "error" } } I whould like to call this function this way Test -foo $foo -bar $bar But if $foo or $bar is $null, exception will be thrown. The ...

Using Many Arguments Without Duplicating Code

Is there a way to use each of the arguments in this function in sequence without duplicating code? For example, the first time through the loop I'd like to use R, the next time I'd like to use L, etc. valuestruct is set up in the same order as the arguments, so the button method will return the equivalent bool I need for currentbutton ...

Interface exposes type A, but implementation requires type B (subclass of A)

I have a system which I've been wrestling with for a while. Essentially, it uses a lot of abstraction to deal with the fact that later extension is not just expected, but necessary. One place this is required is data access. The system generally deals with managing objects encapsulating some observation (in the sense of an observed value...

how to search arguments to find a match to the first argument in c language?

Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument. for example the output would be: ./a 3 h 4 9 3 3 found or ./a hsi and iash me 34 hsi hsi found So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the...

Incompatible pointer type in C language?

I keep getting told that in this line of code passing argument from incompatible pointer type. Here's the line of code: if (linear_search (size_of_A, argv[i])) What does this mean and how do I fix it? Here is the whole program: int linear_search ( int size_of_A, char*argv[]){ int i; i = 2; while (i <= size_of_A - 1...

Is there a way to require that an argument provided to a method is not null?

Is there a better way to require that an argument is not null in a method? I keep checking if any of the arguments that my method requires are null, as show below. But I'm wondering if there is a better way. public void MyMethod(string a, int b) { if(a==null){throw new ArgumentNullException("a");} if(b==null){throw new ArgumentNul...

Passing an array as an argument in C++

I'm writing a merge sort function, and right now I am just using a test case array (there is no input - this is static, for now). I don't know how to pass an array as an argument. Here is my code right now: //merge sort first attempt #include <iostream> #include <algorithm> #include <vector> int mergeSort(int[]); int main() { int orig...

Using Visual Studio macro names to launch external applications doesn't work?

Using Visual Studio / C#, I've been debugging some nunit tests recently, and am now trying to make sure that if we branch the code that the unit tests don't stop working in debug mode. I have this working by changing project properties to launch NUnit as an external program: C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe ..and th...

Setting default value with Params::Validate if an undefined value is passed in

Hi Perl followers. I am having trouble getting Params::Validate to work how I want it to. #!/usr/local/bin/perl -w use strict; use Params::Validate qw/:all/; use Data::Dumper; sub foo { my %args = validate(@_, { bar => { default => 99, # TODO - Somehow use a callback to return a default if undefine...

Objects with arguments and array

Is there a way in C++ where an objects has argument added upon it, with an array such as: int x = 1; int y = 2; Object myObject( x, y )[5]; // does not work I was hoping that I could put arguments into the object, while creating an array of 5 of these objects, does anyone know how? and is there a bteter way? ...