How do I handle an unspecified number of parameters in Scheme?

In Scheme you can use the dot notation for declaring a procedure that receives a variable number of arguments (also known as varargs or variadic function): (define (procedure . args) …) Inside procedure, args will be a list with the zero or more arguments passed; call it like this: (procedure “a” “b” “c”) As pointed … Read more

What is the format of the x86_64 va_list structure?

The x86-64 System V ABi doc may help. It’s a reference, albeit lightweight. The Variable Argument List reference starts on page 54, then it goes on, page 56-57 documents va_list: The va_list Type The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. … Read more

Kotlin convert List to vararg

fun foo(vararg strings: String) { /*…*/ } Using foo(strings = arrayOf(“a”, “b”, “c”)) val list: MutableList<String> = listOf(“a”, “b”, “c”) as MutableList<String> foo(strings = list.map { it }.toTypedArray()) Named arguments are not allowed for non-Kotlin functions (*.java) So, in this case you should replace: From: strings = list.map { it }.toTypedArray() To: *list.map { it … Read more

How are variable arguments implemented in gcc?

If you look at the way the C language stores the parameters on the stack, the way the macros work should become clear:- Higher memory address Last parameter Penultimate parameter …. Second parameter Lower memory address First parameter StackPointer -> Return address (note, depending on the hardware the stack pointer maybe one line down and … Read more

How to wrap a function using varargin and varargout?

Actually, Mikhail’s answer is not quite right. In the case that someFunction is a function that returns a value even if none is requested, which is how a function indicates that the value should be assigned to ans, Mikhail’s wrapper will fail. For example, if someFunction were replaced with sin and you compared running wrapper … Read more

In scala can I pass repeated parameters to other methods?

Java makes an assumption that you want to automatically convert the Array args to varargs, but this can be problematic with methods that accept varargs of type Object. Scala requires that you be explicit, by ascribing the argument with : _*. scala> def bar(args:String*) = println(“count=”+args.length) bar: (args: String*)Unit scala> def foo(args:String*) = bar(args: _*) … Read more

Are there gotchas using varargs with reference parameters

If you look at what va_start expands out to, you’ll see what’s happening: va_start(argptr, format); becomes (roughly) argptr = (va_list) (&format+1); If format is a value-type, it gets placed on the stack right before all the variadic arguments. If format is a reference type, only the address gets placed on the stack. When you take … Read more

How to “pass on” a variable number of arguments to NSString’s +stringWithFormat:

initWithFormat:arguments: NSString *estr(NSString *format, …) { va_list args; va_start(args, format); NSString *s = [[[NSString alloc] initWithFormat:format arguments:args] autorelease]; va_end(args); return s; } they don’t seem to have a convenience constructor “stringWith…” version

Java: Generic method overloading ambiguity

Your 1st case is pretty straight-forward. The below method: public MyContainer<IntWrapper> pack(int key, Object[] values) is an exact match for arguments – (1, String[]). From JLS Section 15.12.2: The first phase (ยง15.12.2.2) performs overload resolution without permitting boxing or unboxing conversion Now, there is no boxing involved while passing those parameters to the 2nd method. … Read more