function

Python func_dict used to memoize; other useful tricks?

A Python function object has an attribute dictionary called func_dict which is visible from outside the function and is mutable, but which is not modified when the function is called. (I learned this from answers to a question I asked yesterday (#1753232): thanks!) I was reading code (at http://pythonprogramming.jottit.com/functional%...

How to write an Emacs function to wrap the marked region with specified text

I'm not too familiar with elisp, and am trying to learn. In emacs, I'd like to be able to do the following: Mark via C-space Go to where I want the the marking to end, so I have a region that is highlighted, suppose it is "highlighted text" Hit a key-sequence Have emacs ask me to input some text, say "plot", and Have that highlighted...

extract the number and name of python method arguments

How can I return the arguments of a function in a different module #Module: functionss.py def simple(a, b, c): print "does something" #Module: extract.py #load the called module and function def get_args(module_name, function_name): modFile, modPath, modDesc = imp.find_module(module_name) mod = imp.load_module(module_name,...

AS3: Accessing custom class public functions from a MovieClip on a timeline

Hi, I've got a AS3 program with a Main.as custom class. In this class I load an instance of a 'menu' movieclip which has simpleButton instances inside... How do I access the Main class public functions by the menu movieclip buttons? I.e. Menu button -> gotoPage(5); (which is a Main public function) If I try to access the Main functio...

Call a function in Vim’s `autocmd` command

I want to use the expand function in an autocmd. In particular, I am adapting a tip by Paul Biggar and I wanted to use the following auto command in my .gvimrc: autocmd FileType tex set makeprg=rubber-info\ expand("%:t:r").log – Which of course doesn’t work. So what I actually want this to mean is that upon opening a tex file, the mak...

Assembly code as an argument to inline assembler in Visual Studio

I need to pass assembly code as arguments in Visual Studio, therefore have a function e.g.: myasm(char *x) that will accept arguments like "mov eax,eax\n add eax,eax" Unfortunately I can't use GCC compiler for what I'm doing. Is there a way to do this in VS? (Note: the assembly code I'm passing is dynamic so I can't predict what it is ...

C - how to check whether all required fields of a structure are filled? (most elegant method)

I have a function, which has a pointer to some structure as its argument. How can I check within this function, whether all required fields of the structure have been filled before a function call? example: //lib.c void f(X_type *x) { ... } //user.c main(){ X_type object; object.name = "I am X"; object.ID = 1; ... f(X_type &object);...

What is the right way to call an Oracle stored function from ado.net and get the result?

I've got a vb.net codebase using ado to connect to an Oracle database. We have lots of stored procedures that we call, some with multiple out parameters. However, I now need to call a stored function, and it's not clear to me how to get the result of the function back into my VB code. Edit: I'm returning an integer. How do I properly c...

jquery synchronous functions

Is there a way to run a function after another functions completes? For example: doSomething(); doSomethingElse(); i only want doSomethingElse() to run after doSomething completes. is this possible? ...

How to know how many words a paragraph contains using Jquery or Javascript? What function?

How to know how many words a paragraph contains using Jquery or Javascript? What function? For example, the sentence How to know how many words a paragraph contains using Jquery or Javascript? contains 13 words. How to count using Jquery or javascript? ...

how to use function(1)(2) in javascript? and how does it work?

I understand calling function(1) but not function(1)(2), how does it work? also possible for function(1)(2)(3)(4) too? ...

Can I choose some(not all) elements in an array and shuffle it in PHP?

Can I choose some elements in an array and shuffle it in PHP? You know, when you use shuffle(array) , It shuffles all elements in an array, but I just want to shuffle some elements in an array while keep other elements unchanged, how to do it? ...

Function names in C++: Capitalize or not?

What's the convention for naming functions in C++? I come from the java environment so I usually name something like: myFunction(...){ } I've seen mixed code in C++, myFunction(....) MyFunction(....) Myfunction(....) what's the correct way? Also, is it the same for a class function and for a function that's not a class function?...

C Function Skipped at Runtime

I have the following C code in a program: printf("Test before print_foo()"); void print_foo(char board[ROW][COL]); printf("Test after print_foo()"); where print_foo printf's the passed in 2-D character array with proper .c and .h files imported. Console output is only the two printf statements. Debugging, the run-time never even step...

Function Pointers in Objective C

Hey Everyone! Quick question. Does anyone know how to get the function pointer of an objective c method? I can declare a C++ method as a function pointer, but this is a callback method so that C++ method would need to be part of the class SO THAT IT CAN ACCESS THE INSTANCE FIELDS. I don't know how to make a C++ method part of an objectiv...

Why does the function on my button not work?

I am writing a form to get data from boxes and do a calculation when the "Calculate" button is clicked. The button does the calculation through the function cal(), but it cannot display the result in the countfield box. How the display the result in the box? Also, how the name the function with "-"? <script type="text/javascript"> func...

How to rearrange this function to return the extended list in Haskell

Hi I am doing problem 68 at project euler and came up with the following code in Haskell to return the list of numbers which fit the (given) solution: lists = [n|n<- permutations [1..6] , ring n ] ring [a,b,c,d,e,f] = (length $ nub $ map sum [[d,c,b],[f,b,a],[e,a,c]]) == 1 This only returns a list of lists of 6 numbers each which f...

F#: Storing and mapping a list of functions

I have a number of events that happen in a game. I want to control the time and order at which these events occur. For example: Event 1: Show some text on screen for N frames & play a sound effect Event 2: Clear the text on the screen My solution (maybe there is a better one), is to have a list of functions that contain the events. ...

How to know how many words a paragraph contains in MySQL?

What MySQL function can I use? for example, What Mysql function can I use? contains 6 words. ...

Issue with scope and closures in JavaScript

My question is really more about scope in JavaScript, rather then closures. Let's take the following code: var f = function () { var n = 0; return function () { return n++; }; }(); console.log(f()); console.log(f()); The above code outputs: 0 1 As you can see from the above code, f (self-invoked) returns a function, creating...