cancel
Showing results for 
Search instead for 
Did you mean: 

Help: kdb-tick mysteries

robinguillaume_
New Contributor
Hi,

I would like to ask you how one of the following lines works:

endofday:{
  end d;
  d+:1;
  if[l;hclose l;l::0(`.u.ld;d)]
};

My probleme is: 0(`.u.ld;d)

I played a bit around to understand but... I guess what it does in this case, but I want to truly understand how it works.

I did : 0({x};1) and I noticed it executes my function {x} with 1 as a parameter. So I can easily infer that it executes .u.ld with d as a parameter.

Do you have any references for that syntax 0()?

I apologize if it's easy to find online... I tried to find information on kx systems documentation, but I didn't find anything.

Thank a lot for your time.

Kind regards,

Guillaume
2 REPLIES 2

sohagan857
New Contributor
Hi Guillaume,

0 is the stdin(console) handle, detailed here


(`.u.ld;d) is a parse tree which is executing .u.ld against param d on the console

More info on parse trees here 


Hth,
Sean

mgaquaq
New Contributor
Hi Guillaume

I'll just build on top of Seans answer.

As you probably already know, you can open handles to q processes using hopen followed by the port number (or the IP address followed by the port number). So for instance, if there was another q process running on port 1234, you could open a handle to it by using h: hopen 1234. Handles in q are represented by integers, so hopen 1234 will just return an integer and h will just be an integer (say, for instance, 7). Normally when sending messages using a handle, you would do something like h "trades", but since h is just an integer, doing 7 "trades" will give exactly the same thing.

Now, the integer 0 represents the handle to the process you are currently in, and allows you to send messages to yourself. For instance, you could do the following:
q)x: 5
q)0 "x"
5


The advantage of this, is that you can use this with the \T command line argument to set a timeout for remotely executed commands. This means that if you want some parts of your script to timeout if they take too long but not others, then you can just send it via the 0 handle. For instance, in the following few lines I am infinitely adding one to zero. In the first case, it times out as I've set the \T command, but in the second case it runs indefinitely.
q)\T 1
q)0 "{1b} (1+)/ 0"
'stop
  [2]  {1b}
       ^
q)){1b} (1+)/ 0
--- process runs indefinitely ---

Hope that clears things up
Matt