# using a self defined dyadic function as infix operator

**URL:** <https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [February 12, 2011, 11:05am UTC](https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978 "2011-02-12T11:05:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 12, 2011, 11:05am UTC](https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978/1 "2011-02-12T11:05:00Z")

</div>

Hi everybody,i would like to store (assign) a dyadic function to a local variableand use it as an infix operator. See the following code snippet:3 {x + y}’ 4;f:{x + y}';3 f 4Here the last line emit an error. How can i avoid this limitation?Thx for your help.Best regards,Kim

---

<div class="post-metadata">

**Author:** ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)\
**Post date:** [February 12, 2011, 11:36am UTC](https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978/2 "2011-02-12T11:36:00Z")

</div>

hi kim,

yes, i’ve found that i can’t “infix” an assigned function,  
but if you’re using an adverb (as in your example) you  
can make it work like this:

q)g:{x+y}  
q)3 g’ 4  
7

---

<div class="post-metadata">

**Author:** ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)\
**Post date:** [February 12, 2011, 11:47am UTC](https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978/3 "2011-02-12T11:47:00Z")

</div>

Am 12.02.2011 12:36, schrieb Jack Andrews:  
\> hi kim,  
\>  
\> yes, i’ve found that i can’t “infix” an assigned function,  
hi Jack,

thanks for your quick reply.

i am the opinion that this can be done, since the built-in function xbar  
is also an assigned function which can be used as an infix operator.

Cheers,

Kim  
\> but if you’re using an adverb (as in your example) you  
\> can make it work like this:  
\>  
\> q)g:{x+y}  
\> q)3 g’ 4  
\> 7  
\>  
\> On Sat, Feb 12, 2011 at 10:05 PM, kuentang wrote:  
\>\> Hi everybody,  
\>\>  
\>\> i would like to store (assign) a dyadic function to a local variable  
\>\> and use it as an infix operator. See the following code snippet:  
\>\>  
\>\> 3 {x + y}’ 4;  
\>\> f:{x + y}';  
\>\> 3 f 4  
\>\>  
\>\>  
\>\> Here the last line emit an error. How can i avoid this limitation?  
\>\>  
\>\> Thx for your help.  
\>\>  
\>\> Best regards,  
\>\>  
\>\> Kim  
\>\>  
\>\> –  
\>\>

Submitted via Google Groups

---

<div class="post-metadata">

**Author:** ![Chris\_Burke1](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Chris\_Burke1](https://forum.kx.com/u/Chris_Burke1)\
**Post date:** [February 12, 2011, 12:44pm UTC](https://forum.kx.com/t/using-a-self-defined-dyadic-function-as-infix-operator/6978/4 "2011-02-12T12:44:00Z")

</div>

A function defined in .q can be infix:q)foo:{x+y}q)2 foo 3 5’typeq).q.goo:{x+y}q)2 goo 3 55 7On Feb 12, 7:47?pm, Kim Kuen Tang \<kuent…\> wrote:\> Am 12.02.2011 12:36, schrieb Jack Andrews:\> hi kim,\>\> \> yes, i’ve found that i can’t “infix” an assigned function,\>\> hi Jack,\>\> thanks for your quick reply.\>\> i am the opinion that this can be done, since the built-in function xbar\> is also an assigned function which can be used as an infix operator.\>\> Cheers,\>\> Kim\>\>\>\>\>\>\>\> \> but if you’re using an adverb (as in your example) you\> \> can make it work like this:\>\> \> q)g:{x+y}\> \> q)3 g’ 4\> \> 7\>\> \> On Sat, Feb 12, 2011 at 10:05 PM, kuentang\<kuent…\> ?wrote:\> \>\> Hi everybody,\>\> \>\> i would like to store (assign) a dyadic function to a local variable\> \>\> and use it as an infix operator. See the following code snippet:\>\> \>\> 3 {x + y}’ 4;\> \>\> f:{x + y}';\> \>\> 3 f 4\>\> \>\> Here the last line emit an error. How can i avoid this limitation?\>\> \>\> Thx for your help.\>\> \>\> Best regards,\>\> \>\> Kim\>\> \>\> –\> \>\>

Submitted via Google Groups\</kuent…\>\</kuent…\>
