f



How to pass a function to a function?, and how to pass the variables of the function?

I'd like to write a function like:

function f(){ ... bla ...}
f_example(f);

function f_example($function_to_execute)
{...bla... $function_to_execute() ...bla....}

AND how to pass the variable of the function :

function f_example($function_to_execute($var1,$var2))
{...bla... $function_to_execute() ...bla....}

Thank you in advance for the time you'll spend for me,
Andrea.


0
9/23/2005 6:14:45 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

6 Replies
1157 Views

Similar Articles

[PageSpeed] 17

I'm sorry, I don't quite understand what you are asking...

If you are asking how to use results of a function in another function 
then you should do this.

function test1()
{
    return "Hello World!";
}

function test2($string)
{

}

test2(test1());
or
$moo = test1();
test2($moo);

Will output *Hello World!*

*****************

If you are asking how you can execute a function inside another 
function, then thats exactly what you do... just call it in the code.

Hope it helps, if not try reading the PHP manual under the 
functions/syntax section.

Cheers,
D



_andrea.l wrote:
> I'd like to write a function like:
> 
> function f(){ ... bla ...}
> f_example(f);
> 
> function f_example($function_to_execute)
> {...bla... $function_to_execute() ...bla....}
> 
> AND how to pass the variable of the function :
> 
> function f_example($function_to_execute($var1,$var2))
> {...bla... $function_to_execute() ...bla....}
> 
> Thank you in advance for the time you'll spend for me,
> Andrea.
> 
> 
0
drybkin (49)
9/23/2005 6:34:33 AM
EDIT!

function test2($string)
{
    echo $string;
}



Ramon wrote:
> I'm sorry, I don't quite understand what you are asking...
> 
> If you are asking how to use results of a function in another function 
> then you should do this.
> 
> function test1()
> {
>    return "Hello World!";
> }
> 
> function test2($string)
> {
> 
> }
> 
> test2(test1());
> or
> $moo = test1();
> test2($moo);
> 
> Will output *Hello World!*
> 
> *****************
> 
> If you are asking how you can execute a function inside another 
> function, then thats exactly what you do... just call it in the code.
> 
> Hope it helps, if not try reading the PHP manual under the 
> functions/syntax section.
> 
> Cheers,
> D
> 
> 
> 
> _andrea.l wrote:
> 
>> I'd like to write a function like:
>>
>> function f(){ ... bla ...}
>> f_example(f);
>>
>> function f_example($function_to_execute)
>> {...bla... $function_to_execute() ...bla....}
>>
>> AND how to pass the variable of the function :
>>
>> function f_example($function_to_execute($var1,$var2))
>> {...bla... $function_to_execute() ...bla....}
>>
>> Thank you in advance for the time you'll spend for me,
>> Andrea.
>>
>>
0
drybkin (49)
9/23/2005 6:40:36 AM
Simple

function a($p)
{
    return $p^2;
}

function b($c, $params)
{
    return $c($params);
}

now pass the function a() to function b() as parameter with additional
param

$func_a = "a";
$result = b($func_a, 123)

thats it!!

0
9/23/2005 8:05:04 AM
On Fri, 23 Sep 2005 06:14:45 GMT, _andrea.l wrote:

> I'd like to write a function like:
> 
> function f(){ ... bla ...}
> f_example(f);
> 
> function f_example($function_to_execute)
> {...bla... $function_to_execute() ...bla....}
> 
> AND how to pass the variable of the function :
> 
> function f_example($function_to_execute($var1,$var2))
> {...bla... $function_to_execute() ...bla....}
> 
> Thank you in advance for the time you'll spend for me,
> Andrea.

Don't multipost, if you have to post to more than one group cross post so
that everyone sees all the answers.
0
Obvious1 (17)
9/23/2005 12:12:46 PM
> Don't multipost, if you have to post to more than one group cross post so
> that everyone sees all the answers.
How can I do to cross post?
Thank you!
Andrea. 


0
9/23/2005 7:54:17 PM
On Fri, 23 Sep 2005 19:54:17 GMT, _andrea.l wrote:

>> Don't multipost, if you have to post to more than one group cross post so
>> that everyone sees all the answers.
> How can I do to cross post?
> Thank you!
> Andrea.

http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
0
Obvious1 (17)
9/24/2005 10:01:35 AM
Reply:

Similar Artilces:

When passing functions as args, how to pass extra args for passed function?
When I pass a function as an arg, like for map(...), how do I pass args to use for that function? If I have a function like this: def pretty_format(f, fmt='%0.3f'): return fmt % f I want to use it with map() like this: formatted = map(pretty_format, unformatted_list) #exept I want fmt='%4.5f' !!! I need to figure out how to pass a non-default value for fmt. How do I do that? On Tue, 16 Sep 2003 17:08:53 -0400 (EDT), rumours say that python@sarcastic-horse.com might have written: >When I pass a function as an arg, like for map(...), how do I pass args to >us...

How to pass a function pointer to a function with std::function parameters
{ Reformatted; please limit your lines to 70 characters -mod } Hi, I am trying to write a little helper template function which takes a std::function object and a parameter and calls the function object and does some additional work. This all works fine until I try to call the template function with a function pointer directly without first creating a temporary std::function object: #include <functional> void globalF(int) { } struct A { void memberF(int); }; template<typename T> void call(std::function<void (A*, T)> func, T x) { A a; func(&a,x); } template<typename T> void call2(std::function<void (T)> func, T x) { func(x); } void good() { std::function< void (int) > f1( globalF ); std::function< void (A*, int) > f2(&A::memberF); call(f2, 0); call2(f1, 0); call<int>(f2, 0); call2<int>(f1, 0); } void bad() { call2(globalF, 0) call( &A::memberF, 0 ); } The code in function bad produces errors: test.cpp: In function 'void bad()': test.cpp:36:20: error: no matching function for call to 'call2(void (&)(int), int)' test.cpp:36:20: note: candidate is: test.cpp:19:27: note: template<class T> void call2(std::function<void(T)>, T) test.cpp:19:27: note: template argument deduction/substitution failed: test.cpp:36:20: note: mismatched types 'std::function<void(T)>' and 'v...

Passing a function-selector into a function
I'm trying to figure out a way to pass a fnc-selector into a fnc `foo' so that the selected-fnc is dispatched efficiently. At the same time, I'm trying to learn how `flet' and `macrolet' work. Invoking foo(3), I'd like `foo' to use its third fnc. This seems to work: (defun foo (selector) (let ((fnc (case selector ... truefnc1 ... truefnc2 ....)) ) (loop repeat LOTSATIMES do (funcall fnc <args>) ) ) ) Is there some way to do this with `flet'? I believe that formulation (defun foo (selector) (flet ((fnc (<args>...

Can I pass functions to functions?
Hi All Can I pass a function to another as a function argument and call it in the second one? For example: function t=f1(a,b,c) .... .... function y=f2(someFunc,u,v,w) .... someFunc(u,v) ..... ... Thanks in advance sohrab wrote: > > > Hi All > Can I pass a function to another as a function argument and call it > in > the second one? Yes. Read up on function handles, or look at how fminsearch or quad use the functions they are supplied. John Thank you very much John! John D'Errico wrote: > sohrab wrote: > > > > > > Hi All > > Can I pass...

passing function into another function
Hi, I couldn't work out the syntax for the following: class Reports def self.This; end def self.That; end end def do_something_with_a_report report # calls Reports::This or Reports::That, dtermined by what report is # something like report.call ? end I want to do something like: do_something_with_a_report Reports::This But that calls Reports::This and sends that value to the do_something_with_a_report function. In other words, I want to do something like passing a function pointer to a function in C. On Tue, 12 Sep 2006, Joe Van Dyk wrote: > Hi, > > I couldn...

Calling functions from functions from functions ...
Lets say I have a function g(p,x) where x and p are of some defined type. I also have a function NewtonR which I can use like so: x = NewtonR(g,p,x0) There is also another function I want to call ImplicitTrap which can be done as: u = ImplicitTrap(g,p,u0,step,n) This function defines a function of g, and it is this function that I'd like to pass to NewtonR. Can it be done? Basically the code is implementing the implicit trapezoidal rule for numerical integration with the NR solver being used at each step with automatic differentiation being used to handle the differentiation. M...

function of a function
Tried to solve numerically: http://groups.google.com/group/sci.math/browse_frm/thread/248f76d024c1ac57/0bba983777a07bc9#0bba983777a07bc9 thus: EQ= { f'[x] == f[f[x]], f[0]== 1} ; NDSolve[EQ,f,{x,0,2}]; But gives an error. NDSolve::ndnum: Differential equation does not evaluate to a number at x = 0. Also does not work even with other f[0] values. Any way to do that? Hi, it can't work because f[0]==1 give in your differential equation f'[0]==f[1] and NDSolve[] can't find the value for f[1] until it has integrated the equation. The neted dependence...

function of a function!!
maybe i hasn't well formulated my question before, so my question is: I have a function f = f(g) where g = g(a,b) is another function, i need, in the function f to use a parameter of the function g (let's say a), is there a way to call the parameter a inside the function f?? thanks In article <ef11409.-1@webx.raydaftYaTP>, rafi <mimosi1@hotmail.com> wrote: > maybe i hasn't well formulated my question before, so my question is: > > I have a function f = f(g) where g = g(a,b) is another function, i > need, in the function f to use a parameter of the func...

Function with a function
I have a GUI that calls a separate function (a different m-file) to perform a certain task. Since this task takes several minutes to complete, I would like to place some frames on the GUI to show progress as the second function runs. These frames would change colors upon getting to certain stages of the code. I am able to get the frames to change color but they do so only after the second function is finished running. Obviously this is no good. A sample of my code is as follows: set(findobj('Tag',['frame2']),'BackgroundColor','green'); This code is contained w...

Functions of Functions
Hello, I was wondering if anyone could help me with this. I've gone through the book and help files as best I can, but can't seem to figure out why the following doesn't work: I'm trying to work with functions that take functions as parameters and return other functions. Below is an example... (*clear stuff*) Clear[a, b, c, x] (*Define a functions a*) \!\(a[x_] := \((Sin[x] + x\^3\/2)\)\) (*define a function of functions*) \!\(b[f_] = \((f'' + \(3\ f'\)\/2 + 5 f)\)\) (*apply the functional function to a*) c = b[...

passing ptr to function to another function
I want a function to execute another function, which I pass to it, sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style. double exec_basecase(void (*func)(double *a, double *b, double *c), double *a, double *b, double *c, int numRowsA, int numColsA, int numColsB) { ...../*other code*/ func(a, b, c); ..... } This is the call in main(): double *a = NULL; double *b = NULL; double *c = NULL; /* allocate memory and initialize matrix */ a = gen_matrix(10, 10, 0); b = gen_matrix(10, 10, 0); c = gen_matrix(10, 10, 0); mflops1[12] = exec_basecase(mm_6r6c_6...

Passing a MATLAB function to a C function
Hi. I have the following setup: 1) a function of several variables implemented in MATLAB which I want to optimize, i.e. to find variable values for which the function gives minimal value, 2) a very good local optimization procedure implemented in C which I want to use repeatedly to optimize the above mentioned function, and 3) a procedure for generating the local search starting points implemented in MATLAB again. Thus, I need to run a MATLAB function which will iteratively generate a starting point and run a C-function local search procedure from that point. I must pass a function defined in MATLAB to that C-implemented local search. Is it possible? The local search procedure is a standard implementation of certain method - it is well possible that by trying to translate it to MATLAB I would not only loose some performance, but also introduce some bogs, which I certainly do not want to. Thanks for any suggestions. Petr Dear Petr, you can feed your C-Mex function with a function handle and call it from the C part with mexCallMATLAB and the 'feval' command. Calling M-code from C is not really fast, so it will be a bottleneck if your function is called millions of times. Good luck, Jan "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <i1mnk6$qud$1@fred.mathworks.com>... > you can feed your C-Mex function with a function handle and call it from the C part with mexCallMATLAB and the 'feval' com...

passing what a function returns to another function
I have 2 functions among others. One gets a URL and returns its, For example, it returns 'http://127.0.0.1' How can I pass this to another function? I've never worked with code that has lots of functions before. def receive_targets_url(): # This recievies the DDOS target's URL I = socket(AF_INET, SOCK_STREAM) I.bind((DDOS_ZOMBIE_IP, U_PORT)) I.listen(5) conn, addr = I.accept() DDOS_TARGET = conn.recv(1024) conn.close() return DDOS_TARGET def receive_commands(): class threaded_ddos(Thread): def run(self): for x in xrange(999999999): ...

Passing member functions to C functions?
I am trying to convert some basic OpenGL code to an OO form. This is the C version of the program: http://www.opengl.org/resources/code/basics/redbook/double.c You can see what my current effort at converting that code to an OO form looks like in the code listed below. The problem I'm running into is that the OpenGL functions that take the names of other functions as arguments don't like the way I'm passing the member functions of my class. I started out making all member functions non-static, but couldn't figure out a way to pass them to functions such as glutDisplayFunc(...

Passing a pointer to a function to the function it points to
I've been doing this sort of thing, and I want to know if it's a sensible way to act (I think this is correct and portable, but want to make sure): int f(int a, void(*b)()) { static int x=0; if(x) return a; x=1; /* do something with a */ ((void(*)(int, void(*)()))b)(a,b); x=0; return a; } Is this one of the few cases where a cast is actually necessary? The idea is that b should be of the same type as f, so it can be called with itself as an argument, but there's no way to write that directly with a finitely-long prototype. One solution might be to do without prototy...

URGENT ! Passing Templates functions to Templates functions
Hello, i am beginner in c++. I hope tobe sufficiently clear and that someone could help me on this topic. For example i have template function <typename T> T sin_func(T & x){return sin(x);} could it be possible that the paramenter of the function is another template function? An example would be very helpful many thanks max [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] In article <cb908b37.0406011422.283669d6@posting.google.com>, ILLOGIC <m_gnesi@yahoo.it> writes >Hello, >...

Syntax for passing an external function into a contained function?
I'm trying to call an external function from a contained function in my subroutine, but no syntax seems to work, I keep getting unresolved externals: main.for external ftest call sub1(ftest) end sub1.for subroutine sub1(func) real*8 func x = func1(n) ... contains real*8 function func1(n) func1 = func(n) return end ftest.for real*8 function ftest(n) ftest = ... return end The linker fails saying func is an unresolved external in func1 but it shouldn't be looking for func, rather ftest which is in the project. ferrad wrote: .... > subroutine sub...

Help! Passing Templates functions to template functions
Hello, i am beginner in c++. I hope tobe sufficiently clear and that someone could help me on this topic. For example i have template function <typename T> T sin_func(T & x){return sin(x);} could it be possible that the paramenter of the function is another template function? An example would be very helpful many thanks max ILLOGIC wrote in news:cb908b37.0406011424.6c0232a0@posting.google.com in comp.lang.c++: > Hello, > i am beginner in c++. I hope tobe sufficiently clear and that someone > could help me on this topic. For example i have template function > > ...

passing S-function parameters from an external function
Hello, I have an .mdl file with an S-function inside. The S-function needs additional parameters passed externally. When running from the Simulink window or thru .m script (using sim), there is no problem. But when running from an external .m function (using sim), my additional parameters are out of scope, so I get an error message. What can I do to pass these parameters to my S-function? Thank you, Israel Zadok. ...

Passing a ParamArray from one Function to another Function
Greetings: I have two functions and I would like to pass the ParamArray gathered from one function to the other function. For the purposes of this post, let's say that they are calculating averages (they're actually processing a sequence of pairs of variants and the sequence is of unknown length). I want something like these two functions: #1 Function AverageSequenceOfNumbers(ParamArray SequenceOfNumbers As Variant) as Double .... End Function #2 Function AverageSequenceOfNumbersPlusOne(ParamArray SequenceOfNumbers as Variant) as Double AverageSequenceOfNumbersPlusOne = AverageSequenceOfNumbers(99, SequenceOfNumbers) End Function The second function is brand new, but the first function is tried-and-true code so I don't want to go back and strip out the ParamArray in the first function and replace it with a regular Array. In fact, I don't want to touch the first function at all (unless it is really minor change). If there is not something obvious then is there a work-around I can implement in the new second function? Thanks, Edlueze. Alas, this is no easy task - in fact, it's pretty much intractible. My response to this issue has been to stop using Paramarray arguments, and instead, take a variant array. The Array function, then makes it easy to pass a custom-built array of values in-line from calling code. That this seems to have been the logic of the ADO API as well, since many ADO methods accept Array values passed to variant arguments. Exa...

MATLAB function name passed in a function call
I have a statement as follows: wc = FWT_PO(x_use,4,QMF) where QMF is the name of a MATLAB function (QMF.m, the Quadrature Mirror Filter function). x_use is an array. The function FWT_PO is just regular MATLAB statements. Problem is that control immediately goes to QMF.m whereupon it bombs out with a "not enough input arguments" error message. Do not understand this form of function call line, cannot find it described in the MATLAB "Help", & thus do not understand cause of the error or how to fix. In article <eed8cdf.-1@webx.raydaftYaTP>, kbannister@ara.com says...

Passing array to a fit function which is being fitted with the function FIT
Hi, my question is: Is there some way of passing arrays to the fit- function? If so how? For those interested in why I need this, read on... I'm using the FIT function of MATLAB to fit a rather intricate function to measured data. The function uses diffraction integrals which are approximated, and then used to calculated the electric field and it's intensity, which is then fitted. Due to the nature of the diffraction integrals, the function is actually a function of the detector coordinates and the object coordinates. Since the electric field at a point of the detector is the sum over all the points in object coordinates (with of course mathematical operations on them), I need to pass these also to the fit- function. So that basically I end up with having to pass the object coordinates in an array as a problem parameter and using the detector coordinates as the predictor. When I do this I get the error: ??? Error using ==> fittype.fittype at 420 Expression fitfunc_simul_gaussian_static (L_norm,x_norm,xp,xpshift,d,sig,r,z,diffdelta,kwave,E0,sigma_factor) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: But loading the coordinates directly inside the fit-function (which is really ugly coding) everything works as expected. So I end up with the above stated question: Is there some way of passing arrays to the fit-function? If so how? Hope someone can help me out. Thanks in advance, Michael Doesn't anyone have any idea/comm...

Template function woes...trouble passing function as argument
Hey everyone, I'm working on an exercise for Accelerated C++ which asked me to implement my own versions of functions such as copy, find, accumulate, etc. Right now I'm working on remove_copy_if. Here's what I have: template <typename In, typename Out, typename F> Out remove_copy_if(In begin, In end, Out dest, F pred()) { while (begin != end) { if (!pred(*begin)) { *dest++ = *begin; } ++begin; } return dest; } This works fine when used with the following: #include <iostream> #include <vector> #include <string> #include "remove_c...

Passing a function name as an argument to a function that calls defadvice?
How do I pass a function as an argument to another function that then uses the argument as a function name to defadvice? Here's what I'd like to do: (defun work-around (arg-function) (defadvice arg-function (around work-around-fn activate) ... before code ... ad-do-it ... after code ... ) ) (work-around 'some-function) However, I can't seem to get some-function into the defadvice call as the function argument. 'arg-function doesn't work either. With the current version, the advice binds to arg-function, not some- function. When I change it to 'a...

Web resources about - How to pass a function to a function?, and how to pass the variables of the function? - comp.lang.php

Talk:Trigonometric functions - Wikipedia, the free encyclopedia
This article is within the scope of WikiProject Mathematics , a collaborative effort to improve the coverage of Mathematics on Wikipedia. If ...

Eating chocolate 'improves brain function' - study
... news for those with a sweet tooth - a recent study has found that regular chocolate consumption is associated with better cognitive function. ...

Using Functions to Make Better Abstractions
... (code that is tightly coupled to its own implementation details). I was wrong. I was wrong because I had an incomplete understanding of functions. ...

Cisco launches new network functions virtualization infrastructure solution to help service providers ...
Al-Bawaba Cisco launches new network functions virtualization infrastructure solution to help service providers run network ... Al-Bawaba ...

Google Maps for iOS adds detour function, 3D touch support
Google has extended its pit-stop feature the ability to find places to stop off on journeys to iPhone and iPad users with the release of Google ...

LVMH's Hublot May Be Next Brand for Smart Functions, Biver Says
Hublot will probably be the next LVMH watch brand to add smart functions, following TAG Heuer’s footsteps in combining Swiss craftsmanship and ...

Yahoo Begins Grim Job of Closing Functions, Laying Off Staff
Yahoo Food is closing, and other digital magazines on tech, travel and beauty are also scheduled for closing or major cutbacks.

Compliance Risk Study Shows Compliance Function Needs New Initiatives to Protect Its Hard-Won Gains
Financial institutions’ compliance functions have come a long way, but they still have some distance to travel before they reach the right strategic ...

A 3D Printed Jet Engine Appears to Function
... jet engine . You may remember seeing a 3D printed jet engine grace our front page back in October. That one was beautiful didn’t function . ...

‘World Of Warcraft’ Alpha Removes Gold From Garrison Missions, Water Striders No Longer Function Everywhere ...
... build deploying soon to the alpha server, garrison missions no longer reward gold and the water-walking Water Strider mounts no longer function ...

Resources last updated: 3/24/2016 12:48:13 AM