arguments

c++: function arg char** is not the same as char*[]

I am using g++. I am using code that had a main(int,char**), renamed so I can call it. I looked at http://stackoverflow.com/questions/779910/should-i-use-char-argv-or-char-argv-in-c, where char** is said to be equivalent to char* []. This does not appear to be true in c++ function calls. For example: void f1(char** p){;} void f2(ch...

Lua: use table as args

Hi, I have numerous functions (unknown at design time) that each take a specific number of arguments. I have a table of arguments. How do I call those functions with this table of arguments? Thanks, James ...

Drupal Views: difference between Filters and Arguments?

What difference between Filters and Arguments? E.g. if I need to show nodes where event_start is located inside specified month, which one should I use? ...

Selecting random phrase from a list

Hi - I've been playing around with a .lua file which passes a random phrase using the following line: SendChatMessage(GetRandomArgument("text1", "text2", "text3", "text4"), "RAID") My problem is that I have a lot of phrases and the one line of code is very long indeed. Is there a way to hold text1 text2 text3 text3 in a list some...

Getting the the keyword arguments actually passed to a Python method

I'm dreaming of a Python method with explicit keyword args: def func(a=None, b=None, c=None): for arg, val in magic_arg_dict.items(): # Where do I get the magic? print '%s: %s' % (arg, val) I want to get a dictionary of only those arguments the caller actually passed into the method, just like **kwargs, but I don't want ...

Is passing multiple sets of arguments as an array in JavaScript faster than multiple function calls?

After becoming slightly uncomfortable with multiple calls to the same function, with different parameters (as shown in the dom ready section of the code below), I decided to test out passing the parameters for this function by iterating through an array instead (as shown in mouse_function_two). To my surprise I found that mouse_function_...

Python normal arguments vs. keyword arguments

Could someone explain the differences to me? Aren't all arguments "keyword arguments"? They all have names, and can all be assigned by that name instead of the position. Do keyword arguments mean ones with default values? (Note: I'm talking about pure python, no C) Thanks. EDIT: I just realized there's two types of each: def func(*arg...

Is it possible to convert a PHP function's parameter list to an array?

Suppose I have a function: function my_function($a, $b, $c) { ... } I want to be able to play with my parameter list as if it were an array - as with here, using a fake $parameter_list variable: function my_function($a, $b, $c) { foreach ($parameter_list as $value) { print $value."\n"; } ... } How can I do t...

How can I convert a PHP function's parameter list to an associative array?

I want to convert the arguments to a function into an associative array with keys equal to the parameter variable names, and values equal to the parameter values. PHP: function my_function($a, $b, $c) { // <--- magic goes here to create the $params array var_dump($params['a'] === $a); // Should result in bool(true) var_d...

OCaml: Default values for function arguments?

In PHP, default values for arguments can be set as follows: function odp(ftw = "OMG!!") { //... } Is there similar functionality in OCaml? ...

Generic Factories and Map Values

I have a class with Maps from Ks to Set<V>s, for several different Vs. I'd like to use a generic factory ala: protected static <T> Set<T> SetFactory(int size) { return new HashSet<T>(size); } to do something like for (K key : keySet) map.put(key, SetFactory()); and have the generic part work (I get a compile error, type misma...

bash script to perform operation on each argument against the final argument

Suppose you want to make a bash script which supports no options but acts like cp, because the cp supplied by your system does not accept multiple sources. The usage for the system's (hypothetical and broken) cp is: cp source target # target may be a directory The usage for the script will be: cp.sh source... target # target m...

Creating a singleton from any given class in javascript

I have written the following function that permits creation of singleton classes from given classes: function SingletonFrom(Constructor) { return function() { var self = arguments.callee; if (self._instance === undefined) { switch (arguments.length) { // this is ugly case 0: self._instanc...

Java method argument puzzle

Hi. I stumbled upon a very puzzling feature(?) of Java. It seems that using a "new" keyword to replace a method argument kind of shifts that object into a different scope: import java.util.ArrayList; public class Puzzle { public static void main(String[] args) { ArrayList<Integer> outer = new ArrayList<Integer>(); ...

C default arguments

Is there a way to specify default arguments to a function in C? ...

Where do you get your PHP documentation from?

Most IDEs come with complete documentation that can be installed locally, but I have a particular problem with PHP, as even the Netbeans PHP IDE links to online docs. How do you manage yours? Is there a hidden downloadable docs for PHP somewhere? ...

passing input from standard input to a file (C programming)

I wrote a program in C which has a function that processes files which can be passed to it by a file pointer. void process_my_file(FILE *fptr, ...) { /* do work */ } I would like to read some input from standard input and pass it to my function, without having to write the input to a temporary file. Would it be possible to pass it ...

buffering when passing input from standard input to a function

I asked about this yesterday, but I'm still having problems. I wrote a program in C which has a function that processes files which can be passed to it by a file pointer. void process_my_file(FILE *fptr, ...) { /* do work */ } I asked how to read input from standard input and pass it to my function, and it was recommended to me th...

DOS: Command-Line Argument Validation

Bear with me, it's been a while. :) What is a good way to validate command-line arguments passed to an MS-DOS batch script? For example, here is what I want to do: IF "%1"=="" throw "Missing 1st argument: Machine Name" IF "%2"=="" throw "Missing 2nd argument: File Path" ...

How to get the nth positional argument in bash?

How to get the nth positional argument in bash? Thanks. Edit: I forgot to say but I meant that n is a variable. ...