cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Passing of functions as arguments

Newbie

Passing of functions as arguments

DOes any know if is possible to pass a function as an argument to another
function in ACL?

I have several functions that perform tree-walks of the document and process
them in various ways. There is a lot of repeated code in these functions
because the only the actual function call to process the element is
different; the code to descend through the document is always the same.

Thanks!

Steve Cogorno Information Products Group
cogorno@sybase.com Sybase, Inc.
Tags (2)
1 REPLY 1

Passing of functions as arguments

At 02:43 PM 2/15/98 -0500, Per-Ake Ling wrote:
>
>> From cogorno@sybase.com Sat Feb 14 06:07:22 1998
>...[snip]
>> DOes any know if is possible to pass a function as an argument to another
>> function in ACL?
>
>I am not sure if the following solves your problem, there is as far
>as I know no way to find the address of a function (like &func in C),

I believe that the *func technique gives you a result similar to using
&func in C, in that in a loop the function name is only evaluated once
and then cached. So if you repeatedly call a function whose name is
passed in as an argument, use this technique.

>however, treating the functionnames as strings or variables work well.
>
>See the following test code:
>================================================
>function func1(msg)
>{
> response("In function 1: " . msg);
>}
>
>function func2(msg)
>{
> response("In function 2: " . msg);
>}
>
>function func3(msg)
>{
> response("In function 3: " . msg);
>}
>
>function func_arg1(f,m)
>{
> eval("$f($$m)");
>}
>
>function func_arg2(f,m)
>{
> # According to ATI docs, the following is more efficient:
> (*f)(m);
>}
>
>function test_funcs()
>{
> local func_arr[];
> func[1]="func1";
> func[2]="func2";
> func[3]="func3";
> eval("$func[1]('Hello1')");
> eval("$func[2]('Hello2')");
> (*func[3])("Hello3");
> func_arg1(func[3],"Calling 3.1");
> func_arg2(func[3],"Calling 3.2");
>}
>================================================
>
>Good luck,
>Per-ÃÂ
ke LIng
>
>
Announcements