argument-passing

defining functions in decorator

Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function? def decorate(f): def new_f(): def gu(): pass f() return new_f @decorate def fu(): gu() fu() Do I need to add gu to a dictionary of defined functions somehow? Or can I add gu t...

How Do I capture a variable (C#)

How Do I capture a variable? Alternatively, can I store a reference to an object reference? Normally, a method can alter a variable outside of it using ref keyword. void Foo(ref int x) { x = 5; } void Bar() { int m = 0; Foo(ref m); } This is clear and straight-forward. Now let's consider a class to achieve the same thin...

Hashes vs. Multiple Params?

It is very common in Ruby to see methods that receive a hash of parameters instead of just passing the parameters to the method. My question is - when do you use parameters for your method and when do you use a parameters hash? Is it right to say that it is a good practice to use a parameter hash when the method has more than one or tw...

Passing a touch event to all subviews of a View Controller

I have a view controller which creates multiple subviews on top of it. All subviews and the view controller accept touches. How can i communicate the touch point information to all the subviews on the screen? Keep in mind that each subview covers the entire screen so after a few additions its a bit like pages in a book. That is, any s...

Passing variables from main form to input form

Hi I have a simple question. I have a main form, and then a startup form from where I can select a new 3D model to generate. When selecting a new 3D model from the startup form, I want to check first whether the previous model I worked on has been saved or not. I simply want to pass a boolean value from the main form to the startup form...

C Variable Scope Specific Question

Here is a particular scenario that I have been unclear about (in terms of scope) for a long time. consider the code #include <stdio.h> typedef struct _t_t{ int x; int y; } t_t; typedef struct _s_t{ int a; int b; t_t t; }s_t; void test(s_t & s){ t_t x = {502, 100}; s.t = x; } int main(){ s_t s; test(s); printf("value i...

Create a Mac Application Installer and Passing Arguments on Launch

Couple questions on creating a mac installer. 1) Should any frameworks from /Developer/SDKs/ be included/packaged into the application file? 2) When we normally launch the executable we pass it an argument to point it at our servers, is there a way to encode this information into the Unix Executable File found in Contents/MacOS/? Than...

Passing parameters dynamically to variadic functions

Hi there. I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function int some_function (int a, int b, ...){/*blah*/} and I am accepting a bunch of values from the user, I want some way of passing those values into the function: some_function (a,b, val1,val2,...,valn) I don...

Execute method with arguments through action mapping in struts 2

How would I execute a method with an argument in my model based on the URL? Ie, http://server/MyAction_Arg.action maps to MyClass.MyMethod(Arg)? I tried this: <action name="MyAction_*" method="MyMethod({1})" class="example.MyClass"> <result>page.jsp</result> </action> but I get java.lang.NoSuchMethodException at runtime ...

passing primitive or struct type as function argument

I'm trying to write some reasonably generic networking code. I have several kinds of packets, each represented by a different struct. The function where all my sending occurs looks like: - (void)sendUpdatePacket:(MyPacketType)packet{ for(NSNetService *service in _services) for(NSData *address in [service addresses]) ...

Passing a structure by reference and manipulating it

typedef struct unit_class_struct { char *name; char *last_name; } person; int setName(person *array) { array[0].name = strdup("Bob"); array[1].name = strdup("Dick"); return 1; } int setLastName(person *array) { array->last_name = strdup("Sanchez"); array++; array->last_name = strdup("Clark"); re...

Modifying a structure array through a pointer passed to a function

I am trying to pass a structure array pointer and a pointer to a structure array pointer into a function and then have it modified rather than using a return. This example code is indeed pointless, its just a learning example for me. Basically I want to create array[0]...array[1]..array[2] and so on and have a pointer that points to t...

Calling pointer-to-member function in call for a function passed to a template function.

This is the provided function template I'm trying to use: template <class Process, class BTNode> void postorder(Process f, BTNode* node_ptr) { if (node_ptr != 0) { postorder( f, node_ptr->left() ); postorder( f, node_ptr->right() ); f( node_ptr->data() ); } } This is my call, and the function I'm passing: v...

Ruby on Rails: Passing argument to singleton

I have a Rails app that repeatedly talks to another Web server through a wrapper, and I'd like to stick the wrapper in a Singleton class so it's not recreated for every request. Easy enough, I thought: class AppWrapper < Wrapper include Singleton end ... wrapper = AppWrapper.instance "url" Only it doesn't work: wrong number of arg...

How to pass a variable from a link to a jQuery function

I would like a jQuery function to know which link was clicked to call it, i.e. I would like the link's id value to be passed to the jQuery function. Is this possible? If so what is the neatest way to do it. ...

jQuery passing variable strange syntax

I have the following two functions: $(".content").click( function() { var id = this.id; $.get("InfoRetrieve", { theid:id }, addContent ); }); function addContent(data){ $("#0001").append(data); } I need to pass the 'id' variable from the first function to the addContent function, I don't quite get how this works. In the a...

How to pass arguments to REXX program through JCL..

Can we pass arguments to a REXX program from JCL? I suppose, JCL PARM can be used as we use for passing arguments to COBOL programs.. Do put your ideas here... ...

Why isn't CodeIgniter passing variables?

What should be happening: user navigates to URI, routes.php grabs the State and sends it to the controller, the controller returns some info from a database query. Pretty basic stuff. The problem: the URI isn't passing the variable to the controller. I'm being told Missing argument 1 for States::state_summary I can set a default f...

pass arguments between shell scripts but retain quotes

How do I pass all the arguments of one shell script into another? I have tried $*, but as I expected, that does not work if you have quoted arguments. Example: $ cat script1.sh #! /bin/sh ./script2.sh $* $ cat script2.sh #! /bin/sh echo $1 echo $2 echo $3 $ script1.sh apple "pear orange" banana apple pear orange I want it to prin...

When to modify and when duplicate arguments?

Consider the functions sort and array_reverse. Why does one modify the variable passed, whereas the other return a new version? $a = array(3, 1, 2); sort($a); // $a === array(1, 2, 3) array_reverse($a); // $a === array(1, 2, 3) sort could just as easily been written to return a modified copy of the argument, and vice-versa for arra...