varargs

Separate NSArray to a list of NSString type objects

A UIActionSheet is initalized with: UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Button1", @"Button2", nil]; I am trying to pass an NSArray into the "otherButtonTitles" message. I tried to pass an NSArray using: ...

JSR223: Calling Java "varargs" methods from script

Hello, I have a method that looks like this on Java: public void myMethod(Object... parms); But I can't call this method as expected from the scripts. If, in ruby, I do: $myObject.myMethod(42); It gives me org.jruby.exceptions.RaiseException: could not coerce Fixnum to class [Ljava.lang.Object If I try the following in Javascrip...

Var-arg of object arrays vs. object array -- trying to understand a SCJP self test question

I'm having trouble understanding this question, and the explanation of the answer for an SCJP 1.6 self test question. Here is the problem: class A { } class B extends A { } public class ComingThru { static String s = "-"; public static void main(String[] args) { A[] aa = new A[2]; B[] ba = new B[2]; sifter(aa); ...

Variable length MATLAB arguments read from variable

I have a function with variable arguments, declared in the standard way: [] = foo ( varargin ) and I would like to call it from another function, but specify the arguments programmatically. My best attempt is something like the following: % bar isn't populated like this, but this is how it ends up bar = { 'var1' 'var2' 'var3' }; foo...

When should I use varargs in designing a Python API?

Is there a good rule of thumb as to when you should prefer varargs function signatures in your API over passing an iterable to a function? ("varargs" being short for "variadic" or "variable-number-of-arguments"; i.e. *args) For example, os.path.join has a vararg signature: os.path.join(first_component, *rest) -> str Whereas min allow...

Wrap a variable parameter function in C++

I would like to wrap the xmlrpc "call" function (which takes a variable number of parameters) with another function (also taking a variable number of parameters). I would like to simply forward the variable number of parameters I get passed in to my wrapper function to the xmlrpc "call" function. I know how to use va_start and va_arg, b...

C varargs - va_copy issues

I'm writing a function in C that takes a variable number of arguments. size_t myprintf(char *fmt, ...); So far, so good. I've decided it's best to do things the Right Way™ and make a version that takes variable arguments, and another version that takes a va_list. size_t myprintf(char *fmt, ...); size_t myvprintf(char *fmt, va_list ar...

Function with variable number of args in C and a design-oriented question

I have a C function named SetParams(...) with a variable number of arguments. This function sets up a static data structure (let us name it Data). SetParams is used with pairs of arguments, e.g. SetParams("paramA", paramA_value, "paramB", paramB_value) etc. It can also be called many times, e.g. SetParams("paramA", paramA_value); SetPar...

Programmatically setting Repeated Parameters in Scala

I'm trying to call Futures.awaitAll with a variable number of well...Futures. awaitAll is defined as awaitAll(timeout : Long, fts : Future[Any]*). I have tried passing in a List and an Array but both won't work: list = future1 :: future2 :: Nil Futures.awaitAll(1000, list) found : List[scala.actors.Future[Any]] required: scala.actors....

Most specific method with matches of both fixed/variable arity (varargs)

In section 15.12.2.5 of the Java Language Specification, it talks about how to choose the most specific method in both cases of methods with fixed arity and methods of variable arity (i.e. varargs). What I can't find in the JLS is anything about deciding between two methods where one is of fixed arity and one of variable arity however....

Var-Args: Last named parameter not function or array?

This question is about vararg functions, and the last named parameter of them, before the ellipsis: void f(Type paramN, ...) { va_list ap; va_start(ap, paramN); va_end(ap); } I was reading in the C Standard, and found the following restriction for the va_start macro: The parameter parmN is the identifier of the rightmost para...

Unrolling var args in AS3

I'm wondering if there is some way to unpack a variable length argument list in AS3. Take for example this function: public function varArgsFunc(amount:int, ...args):Array { if (amount == 3) { return args } else { return varArgsFunc(++amount, args) } } If I call this: var result:Array = varArgs...

How to pass variable number of arguments to a PHP function

I have a PHP function that takes a variable number of arguments (using func_num_args() and func_get_args()), but the number of arguments I want to pass the function depends on the length of an array. Is there a way to call a PHP function with a variable number of arguments? ...

How can Scala receive multiple parameters in a method definition?

Hi, Java has: public void someMethod(int ... intArray) { // question: what is the equivalent to "..." // do something with intArray } how can I achieve the same functionality in Scala? That is, passing an undefined number of parameters to a method? ...

Arrays.asList() not working as it should?

I have a float[] and i would like to get a list with the same elements. I could do the ugly thing of adding them one by one but i wanted to use the Arrays.asList method. There is a problem though. This works: List<Integer> list = Arrays.asList(1,2,3,4,5); But this does not. int[] ints = new int[] {1,2,3,4,5}; List<Integer> list = Arr...

Variable parameter class?

The following code public static void main(String[] args) { fun(new Integer(1)); } static void fun(Object ... a) { System.out.println(a.getClass()); } gives the output :- class [Ljava.lang.Object; What class is this? ...

Get vargs' class type if varg is set to null in Java

How can you get the data type of a variable argument in Java if the varg is set to null? I use the getClass to retrieve the type. Is there any other way? public void method(String name, Object ... vargs) { for(Object arg : vargs) { mapType.put(arg.getClass()); mapVal.put(arg); } } The only thing i could thi...

Is var-args can be used as method argument only???

This is compiling fine :- public class Demo { public static void main(String... args) { } } But this is not getting compiled. public class Demo { public static void main(String... args) { String... strVarArgs ; //here i initiallize strVarArgs by some logic, like we do for arrays } } Plz correct m...

python varargs before function name?

I'm doing some Python coding in a clients code base and I stumbled on a line of code that looks something like this (the variable names have been changed to protect the innocent): reply = function1(a=foo, **function2(bar, b=baz)) Normally ** in the argument list collects remaining keyword arguments but what do they do in front of the ...

Variable number of parameters in function in C++

How I can have variable number of parameters in my function in C++. Analog in C#: public void Foo(params int[] a) { for (int i = 0; i < a.Length; i++) Console.WriteLine(a[i]); } public void UseFoo() { Foo(); Foo(1); Foo(1, 2); } Analog in Java: public void Foo(int... a) { for (int i = 0; i < a.length; i+...