function

How do you pass a function as a parameter in C?

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C? ...

PowerShell - how do I do a string replacement in a function?

How do I convert function input parameters to the right type? I want to return a string that has part of the URL passed into it removed. This works but uses a hard coded string: function CleanUrl($input) { $x = "http://google.com".Replace("http://", "") return $x } $SiteName = CleanUrl($HostHeader) echo $SiteName This fails:...

Best way to convert DateTime to "n Hours Ago" in SQL

I wrote a SQL function to convert a datetime value in SQL to a friendlier "n Hours Ago" or "n Days Ago" etc type of message. And I was wondering if there was a better way to do it. (Yes I know "don't do it in SQL" but for design reasons I have to do it this way). Here is the function I've written: CREATE FUNCTION dbo.GetFriendlyDateT...

In PHP is it possible to use a function inside a variable

I know in php you can embed variables inside variables, like: <? $var1 = "I\'m including {$var2} in this variable.."; ?> But I was wondering how, and if it was possible to include a function inside a variable. I know I could just write: <?php $var1 = "I\'m including "; $var1 .= somefunc(); $var1 = " in this variable.."; ?...

PHP: Can I reference a single member of an array that is returned by a function ?

Hi - any idea how if the following is possible in PHP as a single line ?: <?php $firstElement = functionThatReturnsAnArray()[0]; ... It doesn't seem to 'take'. I need to do this as a 2-stepper: <?php $allElements = functionThatReturnsAnArray(); $firstElement = $allElements[0]; ... just curious - other languages I play with allow th...

C++ overload resolution

Given the following example, why do I have to explicitly use the statement b->A::DoSomething() rather than just b->DoSomething()? Shouldn't the compiler's overload resolution figure out which method I'm talking about? I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.) class A { public: int DoSomething(...

Worse sin: side effects or passing massive objects?

I have a function inside a loop inside a function. The inner function acquires and stores a large vector of data in memory (as a global variable... I'm using "R" which is like "S-Plus"). The loop loops through a long list of data to be acquired. The outer function starts the process and passes in the list of datasets to be acquired. I p...

How to Truncate a string in PHP to the word closest to a certain number of characters?

I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters. I could use substr() to chop off the text at 200 chars, but the re...

Excel Macro Help

I'm looking for assistance in creating an excel macro with the following two functions: Increment or decrement a value based on an action of another field. For example. cell b2 starts out with "0", it will either increment or decrement by "1" if another cell is clicked. Another way is say I have in cell D2, a two way arrow and one end ...

How can I avoid the warning fom an unused parameter in PLSQ?

Sometimes, in PL SQL you want to add a parameter to a Package, Funtion or Procedure in order to prepare future functionallity. For example: create or replace function doGetMyAccountMoney( Type_Of_Currency IN char := 'EUR') return number is Result number(12,2); begin Result := 10000; IF char <> 'EUR' THEN -- ERROR NOT IMPLEME...

Comparing std::tr1::function<> objects

I've been trying to implement a C#-like event system in C++ with the tr1 function templates used to store a function that handles the event. I created a vector so that multiple listeners can be attached to this event, i.e.: vector< function<void (int)> > listenerList; I'd like to be able to remove a handler from the list to stop a ...

How can I generate a list of function dependencies in MATLAB?

In order to distribute a function I've written that depends on other functions I've written that have their own dependencies and so on without distributing every m-file I have ever written, I need to figure out what the full list of dependencies is for a given m-file. Is there a built-in/freely downloadable way to do this? Specifically ...

Good explanation of "Combinators" (For non mathematicians)

Anyone got a good explanation of "combinators" (Y-combinators etc. and NOT the company) I'm looking for one for the practical programmer who understands recursion and higher-order functions, but doesn't have a strong theory or math background. (Note that I'm talking about these things : http://en.wikipedia.org/wiki/Y_combinator ) ...

Tools for finding unused function declarations?

Whilst refactoring some old code I realised that a particular header file was full of function declarations for functions long since removed from the .cpp file. Does anyone know of a tool that could find (and strip) these automatically? ...

Why was the arguments.callee.caller property deprecated in JavaScript?

Why was the arguments.callee.caller property deprecated in JavaScript? It was added and then deprecated in JavaScript, but it was omitted altogether by ECMAScript. Some browser (Mozilla, IE) have always supported it and don't have any plans on the map to remove support. Others (Safari, Opera) have adopted support for it, but support o...

Is there a function in python to split a word into a list?

Is there a function in python to split a word into a list of single letters? e.g s="Word to Split" to get wordlist=['W','o','r','d','','t','o' ....] ...

Javascript curry - what are the practical applications?

I don't think I've grokked currying yet. I understand what it does, and how to do it. I just can't think of a situation I would use it. Where are you using currying in javascript (or where are the main libraries using it)? DOM manipulation or general application development examples welcome. EDIT: One of the answers mentions animation....

What is the standard format for documenting functions in php?

I've written a fair few php apps in the past, but tonight is my first foray into SVN so I figured I'd also document my code properly. What's the adopted format for documenting php functions? Obviously I could adopt my own format, but, looking forward, if there's one which can be used by documentation tools then all the better. Cheers! ...

Classic asp include

Hi I am trying to separate some asp logic out into a separat page. For now i am trying to call a simple function. Here is the simple index page i am using <html> <head> <title>Calling a webservice from classic ASP</title> </head> <body> <% If Request.ServerVariables("REQUEST_METHOD") = "POST" Then %> <!--#include file="aspFunctions...

How to convert an "object" into a function in JavaScript?

JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function. How do you do the reverse, and add a function to an "object"? This works: var foo = function() { return 1; }; foo.baz = "qqqq"; At this point, foo() calls the function, and foo.baz...