function

Passing 2d array to function in Lua

It is possible to pass 2d array to a function as a paramter ? I initialized an array like this : tab={} for i=1, 10 do tab[i]={} for z=1, 10 do tab[i][z]= 0 end end and i have function like this : function foo(data) ... x = data[i][z] -- here i got error ... end The gave the error message attempt to...

MATLAB Piecewise Functions + Vector Manipulation

I would like to write a program which plots the points on top of a semicircle on a certain interval and a straight line everywhere else. Something like this: __n__. I defined a time domain, which was stored as a vector (t = 0:0.01:5). I assumed that I could define the points on the top of the semicircle using elements of the time vector...

return a list<int> from a function c++

Every time I try to use my add function and return a list from it. I get an undefined symbol error. What am I doing wrong here. this is the error: Undefined first referenced symbol in file add(std::list<int, std::allocator<int> > const&, std::list<int, std::allocator<int> >)/var/tmp//...

is there a way to know why php mail function returns false (it happens 'sometimes')

I'm calling php function mail, but it's returning false about 5% - 10% of the times, and it's driving me crazy. I guess from the php side everything is well configured because (correct me if i'm wrong) if not the function should fail every single time. So the question is how can i know the reason of this behavior? What can i do to debu...

PHP: Need to pass variables/functions in a class function for printing layout header! How?

I have a class Page() that I can use to print the (layout) header with. With the function loadHeader($title) I want to be able to print it on all my pages. The actual code for the header is stored in header.inc.php. Now before the header I also want certain variables (like one which maintains a database connection) to be passed along ...

How to put a click function inside a callback function?

I'm using this plugin: http://www.fyneworks.com/jquery/star-rating/ Is it possible to put a click function inside a callback function like this? $('.auto-submit-star').rating({ callback: function(value, link){ $('.myclass').click(function(){ alert($(this).attr('id')); }); alert($(this).attr('id')); } }); The ...

jquery prevent duplicate function assigned

If I need to assign a click function dynamically, is there a way to ensure the click function is only assigned once and not duplicated? this.click(function(){ alert('test'); }) ...

calling function scope mystery

If I have: Object._extends = function(Derived, Base) { Derived.prototype = new Base(); Derived.prototype.constructor = Derived; Derived.uber = Derived.prototype; } var BASE = function() { this._name = "BASE" } var DERIVED = function() { Object._extends(DERIVED, BASE) this._age = 3; } // Object._extends(DERIVED, B...

Ruby: building a plot of function

What's the easiest way to build a plot of a function under Ruby? Any suggestions as to the special graphical library? update: under windows only :-( ...

More vs Less Functions

I had a little argument, and was wondering what people out there think: In C++ (or in general), do you prefer code broken up into many shorter functions, with main() consisting of just a list of functions, in a logical order, or do you prefer functions only when necessary (i.e., when they will be reused very many times)? Or perhaps som...

PHP OOP, perform a function once a certain variable has been set

How can i perform a function once a variable's value has been set? say like $obj = new object(); // dont perform $obj->my_function() just yet $obj->my_var = 67 // $obj->my_function() now gets run I want the object to do this function and now having to be called by the script. Thanks EDIT my_var is predefined in the class, __set ...

Getting WP Functions to Return rather than Printing Immediately

I'm trying to build an array within "The Loop" of values provided from various functions like the_title(), the_excerpt(), the_permalink() and others. I'd like to do something similar to what follows. The unfortunate thing is that most of these functions immediately print their results rather than returning them. Furthermore, I have check...

How can I solve an ODE without using nested functions?

I have some differential equations that I need to solve using MATLAB's ODE solvers. While the differential equations themselves are fairly simple, they depend on a lot of "constants". These constants aren't universal, and need to be supplied by the caller. An example ODE of this sort would be: dx/dt = -j * (k + x) ./ (l + x) Where j,...

Is this the way to go about building Perl subroutines?

So I've had a simple ucwords function for Perl which I've had a while, and wanted to expand it, this is what I've come up with, is this the way I should be building my functions to handle optional parameters? Original: sub ucwords{ $str = @_[0]; $str = lc($str); $str =~ s/\b(\w)/\u$1/g; return $str; } Extended: sub u...

SQL Inline or Scalar Function?

Hi, So I need an SQL function that will concatenate a bunch of row values into one varchar. I have the functions written but right now I'm focused on what is the better choice for performance. The Scalar Function is CREATE FUNCTION fn_GetPatients_ByRecipient (@recipient int) RETURNS varchar(max) AS BEGIN DECLARE @patients varchar(m...

Accessing function from multiple forms on same page.

Hi, I have the following function: <script type="text/javascript"> $(function(){ // start a counter for new row IDs // by setting it to the number // of existing rows var newRowNum = 2; // bind a click event to the "Add" link $('#addnew').click(function() { // increment the counter ...

Call Javascript function from asp.net page in a frame

I have 2 pages in a frameset, in the first page i have a Javascript Function, the second is an asp.net form with a button, the thing is that I need to call the Javascript function in the first page when user clicks the button: I'm trying with: ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script language=JavaScript>p...

Accessing td property of a html table through javascript and css.

I am trying to change the background color of a td element in a static html table. I will be finding the td's invovled through a database call and need to show the td by way of turning the background color from none to yellow. I have built a css file to match the td class attribute so I can isolate the table cell by class id: For exampl...

Property vs Function (specifically .NET)

I've read some discussions about this subject, and there's something I just don't understand. The most common answer seems to be this: use a ReadOnly Property to return cached data, use a Function to return non-cached data. Don't use a WriteOnly Property at all, cause "it doesn't make sense". There is no performance reason for this. In...

Complexity of a given function

When I analyzed the complexity of the code segment below, I found that it is O(n/2). But while searching the internet I discovered that it is probably O(n). I'd like to know who's correct. void function(int n) { int i = 1, k = 100; while (i < n) { k++; i += 2; } } ...