15
голосов
3ответов
23346 просмотров

Passing list to Tcl procedure

What is the canonical way to pass a list to a Tcl procedure? I'd really like it if I could get it so that a list is automatically expanded into a variable number of arguments. So that something like: set a {b c} myprocedure option1 option2 $a and myprocedure option1 option2 b c are equiva...

6
голосов
8ответов
12425 просмотров

What is the meaning of leading underscores in a C++ constructor?

OK I am not a very experienced C++ programmer, but I was wondering what is the significance of the underscores in the arguments of the following constructor? class floatCoords { public: floatCoords(float _x, float _y, float _width, float _height) : x(_x), y(_y), width(_width), height(_h...

3
голосов
5ответов
181 просмотров

Is there an easier way of passing a group of variables as an array

What I'm trying to do is to write a dedicated method for my StreamWriter instance, rather than make use of it at random points in the program. This localises the places where the class is called, as there are some bugs with the current way it's done. Here is what I have at the moment: public st...

19
голосов
8ответов
21098 просмотров

PHP function with unlimited number of parameters

How do I write a function that can accept unlimited number of parameters? What am trying to do is create a function within a class that wraps the following: $stmt->bind_param('sssd', $code, $language, $official, $percent);

3
голосов
4ответов
1645 просмотров

Difference between variable-length argument and function overloading

This C++ question seems to be pretty basic and general but still I want someone to answer. 1) What is the difference between a function with variable-length argument and an overloaded function? 2) Will we have problems if we have a function with variable-length argument and another same name fu...

35
голосов
3ответов
32228 просмотров

String arguments in python multiprocessing

I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters. This is the code: import multiprocessing def write(s): print s write('hello') p = multiprocessing.Process(target=write, args=...

2
голосов
10ответов
5281 просмотров

What arguments does the sizeof operator take in C?

[Original title referred to 'sizeof function'.] I tried these and they all worked: char *p; printf("Size of *p is %d\n",sizeof(*p)); //result =1 printf("Size of p is %d\n",sizeof( p)); //result =4 printf("Size of p is %d\n",sizeof(&p)); //result =4 I wonder why the first printf is ...

47
голосов
8ответов
43680 просмотров

How do you specify a required switch (not argument) with Ruby OptionParser?

I'm writing a script and I want to require a --host switch with value, but if the --host switch isn't specified, I want the option parsing to fail. I can't seem to figure out how to do that. The docs seem to only specify how to make the argument value mandatory, not the switch itself.

8
голосов
12ответов
1399 просмотров

What are good arguments to convince management to upgrade to Delphi 2009 / 2010?

We have a medium-to-large size application. One version runs on Delphi 6 and another one on Delphi 2006. One argument would be support for Unicode. We need that to cater to Customers around the world. Other things I have read about are: better IDE (stability, speed), better Help and some cool...

0
голосов
4ответов
100 просмотров

What do our customers have from migrating from .Net 2.0 to .Net 3.5?

I found very much about the benefits of using a newer .Net version for programmers (LINQ, WPF etc.) but I didn't find anything about the benefits for our customers. So, I'm thinking about migrating our application (WinForms, C#, .Net2.0) from .Net2.0 to .Net3.5 and I need answers to the question...

1
голосов
5ответов
249 просмотров

Python object initialization bug. Or am I misunderstanding how objects work?

1 import sys 2 3 class dummy(object): 4 def __init__(self, val): 5 self.val = val 6 7 class myobj(object): 8 def __init__(self, resources): 9 self._resources = resources 10 11 class ext(myobj): 12 def __init__(self, resources=[]): 13 #m...

-2
голосов
1ответов
26443 просмотров

Too many input arguments in MATLAB

When I run the following code: xdata2 = [1 3 4 5]; ydata2 = [3 9 76 73]; params = [0.1 0.5 0.0 -0.5 0.2 0.8]; y = svenssontest2(xdata2,ydata2,params,0.636,1.9632); I get the error message "Too many input arguments", but the number of input arguments is correct. Here's the code for the function...

1
голосов
1ответов
1002 просмотров

jQuery plugin scope of settings passed in

I feel like this must have been asked, but I'm unable to find it through my searches. Here's a complete example of the issue that's confusing me: <html><head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> &l...

0
голосов
1ответов
287 просмотров

Named and default arguments class arguments in Python

In PHP, I have to pass the arguments in the same order as the arguments are in the constructor. Now, in Python, take listbox = Listbox(root, yscrollcommand=scrollbar.set) for example. If I had passed yscrollcommand=scrollbar.set as the third argument and yscrollcommand was the second argumen...

73
голосов
4ответов
33234 просмотров

How to get the nth positional argument in bash?

How to get the nth positional argument in Bash, where n is variable?

2
голосов
1ответов
3500 просмотров

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"

0
голосов
3ответов
2622 просмотров

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...

2
голосов
3ответов
2559 просмотров

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 tempor...

0
голосов
3ответов
1964 просмотров

Avoid casting from volatile static uint8_t to uint8_t in function calls?

I currently have this code: static void func( uint8_t var ); static volatile uint8_t foo; int main() { /* Here we have to cast to uint8_t */ func( (uint8_t) foo ); /* This will not compile */ func( foo ); } Is there a way to avoid the cast in the function call?

281
голосов
19ответов
211242 просмотров

C default arguments

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

1
голосов
9ответов
1001 просмотров

Java method argument puzzle

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&g...

0
голосов
2ответов
488 просмотров

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 u...

0
голосов
8ответов
1820 просмотров

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...

1
голосов
5ответов
508 просмотров

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())...

1
голосов
3ответов
1227 просмотров

Where to perform argument validation in JavaScript?

Yeah, read properly. In the last time I saw different patterns of argument validation in JavaScript (functions) and wondered which of them would be best-practice. At first I'll show two example code snippets. The first shows an (in my words) "immediate" argument/condition validation and the secon...

6
голосов
4ответов
9387 просмотров

Redirecting output to a command-line argument of another command in Windows

How can I, in Windows, use the output of a script/command as an argument for another script? (A pipe | will not work here, since that other script doesn't read from the standard input) Too clarify: I have AnotherScript that needs an argument arg, e.g.: AnotherScript 12 now I want the argument...

12
голосов
1ответов
5736 просмотров

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?

9
голосов
4ответов
5585 просмотров

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'] === ...

3
голосов
1ответов
315 просмотров

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 $va...

295
голосов
10ответов
253613 просмотров

Normal arguments vs. keyword arguments

How are "keyword arguments" different from regular arguments? Can't all arguments be passed as name=value instead of using positional syntax?