Function From String

Content-Disposition: inline

Hello,

I want to invoke a function on the q server side.

For this reason, I would like to pass a string over to q server that can be interpreted as a function. Later I shall invoke the function remotely.

Is this possible?

Regards,
Yuva

https://code.kx.com/trac/wiki/QforMortals2/i\_o#Interprocess-Communication AttilaOn Mon, Jul 21, 2008 at 11:24 PM, Yuvaraj Athur Raghuvir<yuvaraj.a.r> wrote:> Hello,>> I want to invoke a function on the q server side.>> For this reason, I would like to pass a string over to q server that can be> interpreted as a function. Later I shall invoke the function remotely.>> Is this possible?>> Regards,> Yuva>>>> >></yuvaraj.a.r>

Well, let me take this step by step…:)

  1. I have now created a simple function in a script file named dbpq.q using Wordpad as editor. The contents are as follows:

/l C:q/prj/p1.q
a01:{c: count each value each tables . ;(tables .) @ ? [0 < c;1;0]}

Since the first line has a ‘/’ I assume this will taken as comment.

  1. Then I invoke q on a database using /l command. There are already tables in here and some of them are non-empty

  2. Now I want to load the p1.q script file and use the function a01. As you can see, all it does is find the tables that have non-zero number of records.

Quick Check: If I run the statements in q server, I get the list of tables I want.

Q1: When I load using the first line in q, there is no error. But a01 is not recognized. What am I doing wrong? I am not able to see the function in the context (using value `.) either.
Q2: This method I want to send over the wire. So, I will send the entire second line. This should then be interpreted as a function in the q server and added into the context appropriately

Thanks,
Yuva

The method as defined is not correct…apologies. I am trying to get the index operator in q that needs to be used before the apply verb.
~Yuva

The “where” function seems useful for your purpose:q)t1:(a:(1 2);b:(3 4))q)t2:(a:();b:())q)t3:(c:“xyz”;d:“123”)q)f:{t where 0wrote:> The method as defined is not correct…apologies. I am trying to get the> index operator in q that needs to be used before the apply verb.> ~Yuva>> On Mon, Jul 21, 2008 at 4:02 PM, Yuvaraj Athur Raghuvir <>> yuvaraj....@gmail.com> wrote:> > Well, let me take this step by step…:)> > 1) I have now created a simple function in a script file named dbpq.q using> > Wordpad as editor. The contents are as follows:> > /l C:q/prj/p1.q> > a01:{c: count each value each tables . ;(tables .) @ ? [0 < c;1;0]}> > Since the first line has a ‘/’ I assume this will taken as comment.>> > 2) Then I invoke q on a database using /l command. There are already tables> > in here and some of them are non-empty> > 3) Now I want to load the p1.q script file and use the function a01. As you> > can see, all it does is find the tables that have non-zero number of> > records.> > Quick Check: If I run the statements in q server, I get the list of tables> > I want.>> > Q1: When I load using the first line in q, there is no error. But a01 is> > not recognized. What am I doing wrong? I am not able to see the function in> > the context (using value `.) either.> > Q2: This method I want to send over the wire. So, I will send the entire> > second line. This should then be interpreted as a function in the q server> > and added into the context appropriately>> > Thanks,> > Yuva>> > On Mon, Jul 21, 2008 at 3:27 PM, Attila Vrabecz <attila.vrab…>> > wrote:>> >>https://code.kx.com/trac/wiki/QforMortals2/i_o#Interprocess-Communica...&gt; >> Attila>> >> On Mon, Jul 21, 2008 at 11:24 PM, Yuvaraj Athur Raghuvir> >> <yuvaraj…> wrote:> >> > Hello,>> >> > I want to invoke a function on the q server side.>> >> > For this reason, I would like to pass a string over to q server that can> >> be> >> > interpreted as a function. Later I shall invoke the function remotely.>> >> > Is this possible?>> >> > Regards,> >> > Yuva</yuvaraj…></attila.vrab…>

Thanks. However, when I run just the body of the function I get a `symbol$() error.

q) s: tables . q)s where 0 \< count each value each s: tables .
`symbol$()
q)

Any clues?

Looks like I used the wrong db. It works fine.
Thanks!