# Using K?

**URL:** <https://forum.kx.com/t/using-k/9915>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [June 2, 2015, 7:12pm UTC](https://forum.kx.com/t/using-k/9915 "2015-06-02T19:12:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![refi64](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@refi64](https://forum.kx.com/u/refi64)\
**Post date:** [June 2, 2015, 7:12pm UTC](https://forum.kx.com/t/using-k/9915/1 "2015-06-02T19:12:00Z")

</div>

I have a few questions about using K (not q) in kdb+.

Firstly, I know that you can use a slash to go to K mode in the interactive interpreter:

ryan@DevPC-LX:~$ q

KDB+ 3.2 2015.03.04 Copyright (C) 1993-2015 Kx Systems

l32/ 4()core 5862MB ryan devpc-lx 127.0.1.1 NONEXPIRE &nbsp;

Welcome to kdb+ 32bit edition

For support please see http://groups.google.com/d/forum/personal-kdbplus

Tutorials can be found at http://code.kx.com/wiki/Tutorials

To exit, type \

To remove this startup msg, edit q.q

q)9#!4

'!

q)\

&nbsp; 9#!4

0 1 2 3 0 1 2 3 0

&nbsp;&nbsp;

How do a run a K script? Putting a slash at the top does nothing. I thought:

$ q x.k

would automatically use K because of the file extension…but it doesn’t.

Also, is it possible to access a kdb+ database from K, \*not\* q?

–

Ryan

[ERROR]: Your autotools build scripts are 200 lines longer than your program. Somethings wrong.

http://kirbyfan64.github.io/  
&nbsp;

---

<div class="post-metadata">

**Author:** ![tiagor2010](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@tiagor2010](https://forum.kx.com/u/tiagor2010)\
**Post date:** [June 2, 2015, 8:19pm UTC](https://forum.kx.com/t/using-k/9915/2 "2015-06-02T20:19:00Z")

</div>

Hi,

&nbsp; kdb understands the .k extension and reads it as K code (many Q functions are implemented in the file q.k):

$ **echo ‘9#!4’ \> ./q/a.k**

$ ./q.sh

KDB+ 3.2 2015.04.23 Copyright (C) 1993-2015 Kx Systems

m32/ 8()core 10240MB trodrigues tiagos-macbook-pro.local 172.20.10.2 NONEXPIRE &nbsp;

Welcome to kdb+ 32bit edition

For support please see [http://groups.google.com/d/forum/personal-kdbplus](http://groups.google.com/d/forum/personal-kdbplus)

Tutorials can be found at [http://code.kx.com/wiki/Tutorials](http://code.kx.com/wiki/Tutorials)

To exit, type \

To remove this startup msg, edit q.q

q) **\l a.k**

0 1 2 3 0 1 2 3 0

You can also define K functions in Q (or in a Q script) if you precede it by k) :

q)**k)9#!4**

0 1 2 3 0 1 2 3 0

Note: you can’t mix K and Q code on the same function

Regarding the database, you can, since tables in Q are a flipped dictionary (take a look at q.k). But why would you not use Q for that?

Hope it helps

---

<div class="post-metadata">

**Author:** ![refi64](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@refi64](https://forum.kx.com/u/refi64)\
**Post date:** [June 2, 2015, 8:21pm UTC](https://forum.kx.com/t/using-k/9915/3 "2015-06-02T20:21:00Z")

</div>

On June 2, 2015 2:19:01 PM CDT, Tiago Rodrigues wrote:  
  
\>Hi,  
  
\>  
  
\>kdb understands the .k extension and reads it as K code (many Q  
  
\>functions  
  
\>are implemented in the file q.k):  
  
\>  
  
\>$ _echo ‘9#!4’ \> ./q/a.k_  
  
\>  
  
\>$ ./q.sh  
  
\>  
  
\>KDB+ 3.2 2015.04.23 Copyright (C) 1993-2015 Kx Systems  
  
\>  
  
\>m32/ 8()core 10240MB trodrigues tiagos-macbook-pro.local 172.20.10.2  
  
\>NONEXPIRE  
  
\>  
  
\>  
  
\>Welcome to kdb+ 32bit edition  
  
\>  
  
\>For support please see  
  
\>[http://groups.google.com/d/forum/personal-kdbplus](http://groups.google.com/d/forum/personal-kdbplus)  
  
\>  
  
\>Tutorials can be found at [http://code.kx.com/wiki/Tutorials](http://code.kx.com/wiki/Tutorials)  
  
\>  
  
\>To exit, type   
  
\>  
  
\>To remove this startup msg, edit q.q  
  
\>  
  
\>q)_l a.k_  
  
\>  
  
\>0 1 2 3 0 1 2 3 0  
  
  
  
But can I launch it from the command-line?  
  
  
  
\>  
  
\>You can also define K functions in Q (or in a Q script) if you precede  
  
\>it  
  
\>by k) :  
  
\>  
  
\>q)_k)9#!4_  
  
\>  
  
\>0 1 2 3 0 1 2 3 0  
  
\>  
  
\>  
  
\>Note: you can’t mix K and Q code on the same function  
  
\>  
  
\>Regarding the database, you can, since tables in Q are a flipped  
  
\>dictionary  
  
\>(take a look at q.k). But why would you not use Q for that?  
  
  
  
Just a little experiment…I kind of like k a little better than q. I prefer typing short operators.  
  
  
  
\>  
  
\>Hope it helps  
  
\>  
  
\>On Tuesday, 2 June 2015 19:17:09 UTC+1, Ryan Gonzalez wrote:  
  
\>\>  
  
\>\> I have a few questions about using K (not q) in kdb+.  
  
\>\>  
  
\>\> Firstly, I know that you can use a slash to go to K mode in the  
  
\>\> interactive interpreter:  
  
\>\>  
  
\>\> ryan@DevPC-LX:~$ q  
  
\>\> KDB+ 3.2 2015.03.04 Copyright (C) 1993-2015 Kx Systems  
  
\>\> l32/ 4()core 5862MB ryan devpc-lx 127.0.1.1 NONEXPIRE  
  
\>\>  
  
\>\> Welcome to kdb+ 32bit edition  
  
\>\> For support please see  
  
\>[http://groups.google.com/d/forum/personal-kdbplus](http://groups.google.com/d/forum/personal-kdbplus)  
  
\>\> Tutorials can be found at [http://code.kx.com/wiki/Tutorials](http://code.kx.com/wiki/Tutorials)  
  
\>\> To exit, type   
  
\>\> To remove this startup msg, edit q.q  
  
\>\> q)9#!4  
  
\>\> '!  
  
\>\> q)  
  
\>\> 9#!4  
  
\>\> 0 1 2 3 0 1 2 3 0  
  
\>\>  
  
\>\> How do a run a K script? Putting a slash at the top does nothing. I  
  
\>\> thought:  
  
\>\>  
  
\>\> $ q x.k  
  
\>\>  
  
\>\> would automatically use K because of the file extension…but it  
  
\>doesn’t.  
  
\>\>  
  
\>\> Also, is it possible to access a kdb+ database from K, _not_ q?  
  
\>\>  
  
\>\> –  
  
\>\> Ryan  
  
\>\> [ERROR]: Your autotools build scripts are 200 lines longer than your  
  
\>\> program. Somethings wrong.  
  
\>\> [http://kirbyfan64.github.io/](http://kirbyfan64.github.io/)  
  
\>\>  
  
\>\>  
  
  
  
–  
  
Sent from my Android device with K-9 Mail. Please excuse my brevity.

---

<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:** [June 2, 2015, 8:46pm UTC](https://forum.kx.com/t/using-k/9915/4 "2015-06-02T20:46:00Z")

</div>

q a.k

should work fine
