function

Vector algebra in functional

How to implement vector sum, using functional programming in python. This code work for n <100, but not for n > 1000. from itertools import * #n=10000 # do not try!!! n=100 twin=((i,i**2,i**3) for i in xrange(1,n+1)) def sum(x=0,y=0): return x+y def dubsum(x,y): return (reduce(sum,i) for i in izip(x,y) ) print [ i for i in r...

Set a timeout for a specific function / block of code (not the whole script)?

I have php scripts that call perl scripts to do various things and sometimes I get it where it just goes on and on without getting a response back, this is based on the variable that is being passed to the perl script and I am doing a lot of different ones in succession so I can't get really debug it directly since I don't have a respons...

Adjusting a php function so that it displays link in the form of:- '/widgets?pg=2' instead of 'products.php?cat=20&pg=2'

I added the following .htaccess rule:- RewriteRule ^widgets$ products.php?cat=20 [QSA] So now I have a simple link called 'widgets' which leads to the 'widgets' category 1st page. However, the links to the 2nd page looks like the following:- products.php?cat=20&pg=2 What I would like is for the subsequent pages to be rather in th...

can we pass arrays as arguments to functions by this syntax, under upcoming c++0x standards ?

suppose we have following function: void someFunction(int * araye){ for (int i=0;i<5;i++) cout <<araye[i]<<' '; cout <<'\n'; } can we pass an array to this function by following syntax, under upcoming c++0x standards? : someFunction({1,2,3,4,5}); if that's true, will we even be able to use this syntax in any case in which, arra...

How do I get the same functionality as C's __FUNCTION__ in Python?

In C, I can put a log printf inside a function like this: void xx_lock (int xx_flag) { printf ("%s: START with %d\n", __FUNCTION__, xx_flag); } so I can copy the same line where I need in any function and it displays the function name in the log. I want something similar in Python. But if I use __name__ the same way, it displays ...

Getting return value of a function called with assembly

I am using Microsoft Visual C++ 2010. If I have a function like this: const char* blah(void); and I want to call it like this: __asm { call blah; ... } How do I get the return value of the function in the assembly? ...

How to call objective-C function from a C function

I'm trying to call an objective-C function from a C function but the code keeps crashing in objc_msgSend. My objective-C class is a singleton and I'm using the following code. void c_function(int arg0, const char *arg1) { [[objc_class instance] testFunction:arg0 Arg1:arg1]; } The gdb shows the crash is happening when object...

JavaScript form input loop help

Hello, I have a form that currently only parses the first input variable in the POST. I have had to add multiple variables, so I would like the function to loop through and grab all the input parameters and add to the POST Here's the working code for grabbing the first name and value.... How can I get it to check the form and grab all ...

function __autoload & using require_once / ignore certain instances

Hi everyone, I am using the autoload function for a certain library... But I am trying to implement Doctrine and I am getting a 500 Internal Server Error. I believe its because I am creating = new instance and in the autoload... It checks a different directory. Is there a way to create new instances of classes that will ignore the au...

Strange C construction encountered in academic paper

The code states: void (* log_msg)(char *msg) =printf; void change_and_log(int *buffer, int offset, int value){ buffer[offset] = value; log_msg("changed"); } I'm most concerned with the first part: Firstly, what does the signature void (* log_msg)(char *msg) mean? Is this code simply mapping the function log_msg to print...

Howto import a function with python

I'm developing a Python application for the GAE. The application consists of a bunch of classes and functions which are at the moment all in the same file main.py. The application is running without problems. Now, I want to refactor the application and outsource all the classes. Every class should be in her own file. The files shall ...

Define function name with text field

Hi, I'm only really a novice with PHP (and I know I'm sortof trying to run before I can walk), but I would like to know if it is possible to define a functions name via a textfield. Currently, I am working with Wordpress so I can use add_option to add something to the database to store data, etc, which is handy. My idea is for a slidesh...

extend jquery plugin object with functions

so im trying to write a new jquery plugin. base (this is not my plugin, just for better understanding): (function($) { $.fn.mySuperCoolPlugin = function(options) { // Build main options before element iteration var opts = $.extend({}, $.fn.mySuperCoolPlugin.defaults, options); var editText= 'pre ' + opts....

Shortest way of creating a "new function" alias in javascript

What's the shortest way (characters) of creating a "new function" alias. Basically this is for code golf and minifying code beyond reason. So when you usually would write: a=function(a,b,c){return a+b+c;} You could write something like (also let's abstract return keyword as well with global variable R): a=$("a,b,c","R=a+b+c") a=$(a,...

Creating functions in a loop

I'm trying to create functions inside of a loop and storing them in a dictionary. The problem is that all entries in the dictionary seem end up mapping to the last created function. The code goes like this: d = {} def test(**kwargs): for k in kwargs: def f(): print k, kwargs[k] d[k] = f f() test...

Are clojure function cyclic dependencies specifically disallowed by design, or is it just a reader behaviour?

If I do the following in clojure (defn sub1a [a] (cond (= a 0) 0 true (sub1b (- a 1) ))) (defn sub1b [a] (cond (= a 0) 0 true (sub1a (- a 1) ))) (println (sub1a 10)) I get the following error: java.lang.Exception: Unable to resolve symbol: sub1b in this context But if I do the following: (defn sub1a [a] (co...

How to make a load response have several conditions in it?

Hi there I have a function function preloadImage() { varLink=".... link to my picture..." $("#picture").attr("src", varLink).one("load", function() { // This is called after the image is loaded }} Now I call this function many times in my jquery script. But I need it to call different functions after the image is loaded. Is there ...

MATLAB function input argument

I am facing problem in passing a vector to a matlab function defined in m file.someone told me that only single value variables can be passed as arguments to a function, not vector/array/matrix? Is it true ? If true then matlab is of no use? please help me... thanking you ...

PHP function call not working - presumed casting problem?

Why does THIS not work when called via e.g. wd(1) (it always returns '-2')? $zoom=$user['zoom']; function wd($hrs){ return $hrs*$zoom-2; } But THIS works fine: function wd($hrs){ return $hrs*30-2; } Assuming this was a casting problem, I tried all sorts of variations like (int)$hrs * ((int)$zoom) or (int)$hrs * (float)$zoom...

Why are functions in JavaScript set to global variables instead of plain functions?

I am wondering if anyone knows why some people define global variables that are set to functions vs just defining a global function name. For example: var foo = function() { alert('hello!'); } instead of function foo() { alert('hello!'); } Wouldn't the second method be better since there is a chance something might overwrite the f...