reading from stdin

Is there a way to read data from stdin? Some of the tables I’m workingwith are essentially code and it’s inconvenient to carve them out intotiny little text files. The usual column-oriented definitions seem alittle odd too when the data to be represented is a set of tuples. Ihaven’t found anything in the documentation that shows how to readdata from stdin (e.g., a script).Here’s an example to illustrate what I’d like to do:fsm:(“III”;enlist “,”)0: ``ENDs0,symbol,s10, 0, 10, 1, 01, 0, 01, 1, 1ENDWhere the symbol END would be the boundary of the “here table”.

X-Mailer: Apple Mail (2.936)kdb is not really a general purpose shell. “here document” shell feature is not implemented and i think it will never be.On 3 Oct 2009, at 08:55, andyturk wrote:>> Is there a way to read data from stdin? Some of the tables I’m working> with are essentially code and it’s inconvenient to carve them out into> tiny little text files. The usual column-oriented definitions seem a> little odd too when the data to be represented is a set of tuples. I> haven’t found anything in the documentation that shows how to read> data from stdin (e.g., a script).>> Here’s an example to illustrate what I’d like to do:>> fsm:(“III”;enlist “,”)0: ``END> s0,symbol,s1> 0, 0, 1> 0, 1, 0> 1, 0, 0> 1, 1, 1> END\>\> Where the symbol END would be the boundary of the “here table”.>> >

X-Mailer: iPhone Mail (7C144)Subject: Re: [personal kdb+] Re: reading from stdinDate: Sat, 3 Oct 2009 09:16:19 -0400Cc: “personal-kdbplus@googlegroups.com” You can read from stdin though:x:read0 0On Oct 3, 2009, at 6:20 AM, Felix Lungu <felix.lungu> wrote:>> kdb is not really a general purpose shell. “here document” shell> feature is not implemented and i think it will never be.>> On 3 Oct 2009, at 08:55, andyturk wrote:>>>>> Is there a way to read data from stdin? Some of the tables I’m >> working>> with are essentially code and it’s inconvenient to carve them out >> into>> tiny little text files. The usual column-oriented definitions seem a>> little odd too when the data to be represented is a set of tuples. I>> haven’t found anything in the documentation that shows how to read>> data from stdin (e.g., a script).>>>> Here’s an example to illustrate what I’d like to do:>>>> fsm:(“III”;enlist “,”)0: ``END>> s0,symbol,s1>> 0, 0, 1>> 0, 1, 0>> 1, 0, 0>> 1, 1, 1>> END&gt;&gt;&gt;&gt; Where the symbol END would be the boundary of the “here table”.>>>>>>>> ></felix.lungu>

If you really wanted a project, you could probably modify q.k or write your own language to enable something like this. You can also write a C function and load it in to accept keyboard input where enter does not terminate the string.

On Oct 3, 2009, at 1:55 PM, andyturk wrote:

> Is there a way to read data from stdin? Some of the tables I’m working
> with are essentially code and it’s inconvenient to carve them out into
> tiny little text files. The usual column-oriented definitions seem a
> little odd too when the data to be represented is a set of tuples. I
> haven’t found anything in the documentation that shows how to read
> data from stdin (e.g., a script).
>
> Here’s an example to illustrate what I’d like to do:
>
> fsm:(“III”;enlist “,”)0: ``END
> s0,symbol,s1
> 0, 0, 1
> 0, 1, 0
> 1, 0, 0
> 1, 1, 1
> `END

the closest you can really come to a table literal in q is to insert a
row at a time and use whitespace to make it kind of look like a table:

% cat fsm.q
fsm:flips0symbols1!flip 3#enlist 0#0 fsm upsert(
0 0 1;
0 1 0;
1 0 0;
1 1 1
);
show fsm
% q fsm.q
KDB+ 2.6 2009.09.15 Copyright (C) 1993-2009 Kx Systems
m32/ 2()core 2048MB

s0 symbol s1

0 0 1
0 1 0
1 0 0
1 1 1
q)

otherwise, yeah, you’ll have to hack on the language somehow if you
really want “here-tables” in q

unfortunately the best place to implement that would probably be in
the preprocessing function that handles comments:

k){x:(“#!”~2#*x)_x:-1!‘x;y{0N!x
y}’" “/:'(&~^*:'x)_x@:&(#:'x)&~”/“=*:‘x@:&~|’:(b?-1)#b:±/x~:/:+,”/
";}

but seems to be an internal function hard coded in the q binary, and
so not override-able.

you can see it by feeding a malformed file to q and signaling up the
stack:

% cat foo.q
a:
% q foo.q
KDB+ 2.6 2009.09.15 Copyright (C) 1993-2009 Kx Systems
m32/ 2()core 2048MB

k){0N!x y}
‘a
@
“q”
“a:”
q))’
k){x:(“#!”~2#*x)_x:-1!‘x;y{0N!x
y}’" “/:'(&~^*:'x)_x@:&(#:'x)&~”/“=*:‘x@:&~|’:(b?-1)#b:±/x~:/:+,”/
";}

q))

you might be able to construct a small language which would transform
here-tables into ordinary hard-coded q tables, then pass the code to q
for further processing, but i wouldn’t have any idea how to do that,
beyond advising you to read and understand q.k and s.k

> … see it by feeding a malformed file to q and signaling up the stack …Goat’s blood and chicken feathers, I think. ;-)I like your upsert idea though, which uses q’s standard reader toaccomplish95% of what the “here document” approach would need to implement.Cool. Thanks!fsm:(s0:int$();symbol:int$();s1:`int$()) upsert (/ s0 symbol s1/------------- 0 0 1; 0 1 0; 1 0 0; 1 1 1)