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