# a question from KDB beginner

**URL:** https://forum.kx.com/t/a-question-from-kdb-beginner/7268
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [September 2, 2011, 10:43am UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268 "2011-09-02T10:43:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Wei\_Li](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Wei\_Li](https://forum.kx.com/u/Wei_Li)
#### Post date: [September 2, 2011, 10:43am UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/1 "2011-09-02T10:43:00Z")

</div>

Hi everyone,Recently I started to learn KDB, and I saw some working codes asfollowinghCx:hopen `:eqkdb8p:12000hCx({select cnt:count i from corrTab};::)I tried to run them in q session and they work very well. The firstline is just to connect to KDB host. But the second line is veryconfusing. Especially corrTab is neither a q keyword nor a variable/table defined. Why it works and print outcnt-------9415683Can anyone help?Thanks

---

<div class="post-metadata">

### Author: ![trieder](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@trieder](https://forum.kx.com/u/trieder)
#### Post date: [September 2, 2011, 11:15am UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/2 "2011-09-02T11:15:00Z")

</div>

charset=us-ascii  
X-Mailer: iPhone Mail (8F190)  
In-Reply-To: \<2195d485-eab1-469b-a976-05febf6114cf@x21g2000prd.googlegroups.com\>  
Message-Id: \<23D30AB2-FA80-4B27-80DA-0E85D33B4C16@gmail.com\>  
Date: Fri, 2 Sep 2011 06:15:43 -0400  
To: “[personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)”   
  
Mime-Version: 1.0 (iPhone Mail 8F190)  
  
For you to understand this you need to read the manuals or q for mortals. In=  
 particular the sections on ipc, data types (in this case lists) and functio=  
ns.  
  
In a nutshell it’s sending a function to the remote host which is simply exe=  
cuting the query.

---

<div class="post-metadata">

### Author: ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)
#### Post date: [September 2, 2011, 11:26am UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/3 "2011-09-02T11:26:00Z")

</div>

hCx ({select cnt:count i from corrTab};::)

is sending the list&nbsp;({select cnt:count i from corrTab};::) to the socket referred to by hCx.

({select cnt:count i from corrTab};::)

is a 2 element list, a&nbsp;lambda (anonymous function) and identity (::).

It’s possible to evaluate a single level parse tree as

q)value ({x+y};2;3)

and that’s what is happening here, except&nbsp;({select cnt:count i from corrTab};::) is being recompiled and evaluated remotely.

Presumably corrTab is defined on the remote system.

---

<div class="post-metadata">

### Author: ![rathore\_ajay1](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@rathore\_ajay1](https://forum.kx.com/u/rathore_ajay1)
#### Post date: [September 2, 2011, 1:16pm UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/4 "2011-09-02T13:16:00Z")

</div>

In this case, you are connecting to a different kdb process andsending an anonymous function {select cnt:count i from corrTab} andidentity to be executed in that process. So here corrTab is a tabledefined the q process running on eqkdb8p at port 12000. This isequivalent to executing this query on that remote process “selectcnt:count i from corrTab”. Hope this answers your question.Another way to do the same thing would behCx:hopen `:eqkdb8p:12000hCx "select cnt:count i from corrTab"On Sep 2, 5:43?am, Wei Li <lavi...> wrote:&gt; Hi everyone,&gt; Recently I started to learn KDB, and I saw some working codes as&gt; following&gt;&gt; hCx:hopen `:eqkdb8p:12000\> hCx({select cnt:count i from corrTab};::)\>\> I tried to run them in q session and they work very well. The first\> line is just to connect to KDB host. But the second line is very\> confusing. Especially corrTab is neither a q keyword nor a variable/\> table defined. Why it works and print out\>\> cnt\> -------\> 9415683\>\> Can anyone help?\> Thanks\</lavi…\>

---

<div class="post-metadata">

### Author: ![Aaron\_Davies](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@Aaron\_Davies](https://forum.kx.com/u/Aaron_Davies)
#### Post date: [September 2, 2011, 6:44pm UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/5 "2011-09-02T18:44:00Z")

</div>

\> Another way to do the same thing would be  
\>  
\>  
\> hCx:hopen `:eqkdb8p:12000  
\> hCx “select cnt:count i from corrTab”

slightly more precisely,

hCx “{select cnt:count i from corrTab}”

sending (::) as an arg is the equivalent of invoking with

–  
Aaron Davies  
aaron.davies@gmail.com

---

<div class="post-metadata">

### Author: ![Wei\_Li](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Wei\_Li](https://forum.kx.com/u/Wei_Li)
#### Post date: [September 7, 2011, 1:59pm UTC](https://forum.kx.com/t/a-question-from-kdb-beginner/7268/6 "2011-09-07T13:59:00Z")

</div>

Thanks all for help.Now I understand it.On Sep 3, 1:44?am, Aaron Davies \<aaron.dav…\> wrote:\> \> Another way to do the same thing would be\>\> \> hCx:hopen `:eqkdb8p:12000\> \> hCx “select cnt:count i from corrTab”\>\> slightly more precisely,\>\> hCx “{select cnt:count i from corrTab}”\>\> sending (::) as an arg is the equivalent of invoking with \>\> –\> Aaron Davies\> [aaron.dav...@gmail.com](mailto:aaron.dav...@gmail.com)\</aaron.dav…\>
