calling function by reference

i want to be able to call a function by reference, for example:

f1:{…}
f2:{…}

can i do something that in C would look like:

void (*f)() = &f1; //point f to f1
(*f)(); //call f1 via reference

i could probably use eval, but is there other way?

thank you
Alex

Do you mean this?

q)f:{x+2}

q)`f 2

4

Regards,

Fintan.

On Jan 22, 1:14?am, AlexB <4571…@gmail.com> wrote:> i want to be able to call a function by reference, for example:> can i do something that in C would look like:>> void (*f)() = &f1; ?//point f to f1> (*f)(); ?//call f1 via referenceIn q, you essentially already have references to functions. I.e., whenyou write:f:{… some code …}the variable named “f” is bound to a reference to a literal function.You could also bind “f” to a built-in:q)f:+q)f[2;2]4Or make lists of functions:q)fns:(+;*;%;{2*x+y})q)fns[1][333;10]3330

On Jan 22, 8:59?am, Fintan Quill <fint…> wrote:> q)f:{x+2}> q)f 2&gt; 4Interesting.q)f:{x+2}q)f 24q)g:fq)g 24q)g 2’type</fint…>

On Jan 21, 2011, at 10:28 PM, andyturk wrote:

> On Jan 22, 8:59 am, Fintan Quill <fint…> wrote:
>> q)f:{x+2}
>> q)f 2<br>&gt;&gt; 4<br>&gt; <br>&gt; Interesting.<br>&gt; <br>&gt; q)f:{x+2}<br>&gt; q)f 2
> 4
> q)g:f<br>&gt; q)g 2<br>&gt; 4<br>&gt; q)g 2
> 'type

yeah it’s only one layer



</fint…>

If you can think of symbols as being analogous to C pointers rather
than C++ references, then think of “value” as the q analogue to C’s
dereferencing operator, “*”:

q)value[`g]2
4

ACS

On 22 Jan 2011, at 05:28, andyturk wrote:

> q)g:f \> q)g 2 \> 4 \> q)g 2
> 'type

this would have been a double indirection if it would have been working
but in this case it was interpreted as atom indexing.