Forum Replies Created

Page 12 of 16
  • Laura

    Administrator
    April 7, 2022 at 12:00 am in reply to: Running Entry Count

    Not entirely clear what youre looking for here. If you want to produce a 1N list for each symbol you can use til and avoid the sums and comparisons:

     

    q)select 1+til count i by sym from t 
    sym | x 
    ----| --------------- 
    aapl| 1 2 3 4 5 
    goog| 1 2 3 4 5 6 7 8 
    msft| 1 2 3 4 5 6 7

     

    but its hard to see a use for the lists. Perhaps you simply want to count rows for each symbol?

    q)exec count i by sym from t 
    aapl| 5 
    goog| 8 
    msft| 7 
    q)ts:1000 select sums i=i by sym from t 
    4 10720 
    q)ts:1000 exec count i by sym from t 
    1 9584

     

     

  • Laura

    Administrator
    April 6, 2022 at 12:00 am in reply to: Running Entry Count

    sums i=i by sym

    did the trick

  • Laura

    Administrator
    April 5, 2022 at 12:00 am in reply to: Q 4.0 can’t have space in command line argument

    As does my later version.

    ? q4.0 -args '12 34' KDB+ 4.0 2021.11.04 Copyright (C) 1993-2021 Kx Systems m64/ 12()core 65536MB sjt mackenzie.local 127.0.0.1 ... 
    q).z.x "-args" "12 34"
  • Laura

    Administrator
    April 5, 2022 at 12:00 am in reply to: Window Join w/ Multiple Symbols

    that was it, thanks!

  • Laura

    Administrator
    April 5, 2022 at 12:00 am in reply to: Window Join w/ Multiple Symbols

    Yeah, I took a look at aj but ultimately wj just better suites my needs.

    So I’ve got the tables sorted “sym “time but seem to be missing on the `p# part (pun maybe intended).

    How does one `p# a column in a table properly?

  • Laura

    Administrator
    April 5, 2022 at 12:00 am in reply to: 1 "hello" return hello1

    To enlarge on Rians answer, the hello1 you see is not the result. The string hello is written to the console. The result 1 is also written to the console and followed by a newline as usual. Assigning the result makes the difference clear.

     

    q)1 “hello”

    hello1

    q)a:1 “hello”

    helloq)

    q)a 1

    q)

     

     

  • Laura

    Administrator
    March 18, 2022 at 12:00 am in reply to: What are these errs?
  • Laura

    Administrator
    March 18, 2022 at 12:00 am in reply to: Have I developed the functional equivalent of a Boolean gate?

    Youre infested with parens! They might be confusing you.

    First, those multiple right parens in the prompts: thats not q trying to look like Python. Each right paren after the initial q) indicates a suspended evaluation with associated state. Unless youre exploring that state, best to cut back the stack with a backslash lest you find names resolving in suspended state. (No sign of that here, but its good practice.)

     

    q){(x*y)-1 y*x}[0;0] 'type [1] {(x*y)-1 y*x} 
    ^ 
    q)) x / suspended state 0 
    q)) 
    q)x / suspension cleared, no value of x 'x [0] x / suspension cleared, no value of x 
    ^

     

    Second, redundant and missing parens in your lambda indicate the syntax is new to you. The most important syntactic rule is that there is no hierarchy of functions. Operators are binary functions with infix syntax. They have short left scope and long right scope. The left argument is the value immediately on the left. The right argument of an operator, or the argument of a unary function, is the result of evaluating everything to its right. Famously:

     

    q)3*4+5 27

     

    Syntactically, a republic of functions. No precedence rules to remember. Just the above. (One rule to rule them all)

    IO handles are integers. When you hopen a file or IO stream the handle for it is an integer and the integer behaves like a function. You can apply it. When you apply a file handle to an argument, the argument gets written to the file. The integers 0, 1, and 2 permanently refer respectively to the console, stdout, and stderr.

    So (x*y)-1 ((y)*x) tries to write y*x to stdout. (Oops, type error, needs to be text.)

    Understanding this, we can rewrite your tests:

    q){(x*y)-y*x}[0;0] 0 
    q){(x*y)-y*x}[0;1] 0 
    q){(x*y)-y*x}[1;1] 0

     

    None of which will surprise you.

    To continue your exploration you might like to use Each Right Each Left /:: with a lambda to tabulate results:

     

    q)10 20 30 +/::1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 
    q)0 1{(x*y)-y*x}/::0 1 0 0 0 0

     

  • Laura

    Administrator
    March 18, 2022 at 12:00 am in reply to: Function return notation.

    Two expressions: one multiplies 0+0 by 1%0&0; the other adds them.

    The sum of two long zeros is long zero.

    1%0 is float infinity 0w. The type of the right argument does not matter; Divide always returns a float.

    So the comparison is between 0*0w and 0+0w.

    The latter is 0w. Surely expected: infinity plus x is infinity.

    The unexpected result then is 0*0w. Is not 0*x always zero? But here its a float null 0n. I do not know the mathematical justification for this; perhaps someone else can shed light?

    BTW your lambdas could be simpler:

    test1:{(x+y)*1%x&y} 
    test2:{(x+y)+1%x&y}

     

     

     

     

  • Laura

    Administrator
    March 18, 2022 at 12:00 am in reply to: cols t vs key flip value t

    Perhaps the author was trading memory for speed?

    q)t:flip(`$'.Q.a)!26 10000000#26000000?1000 
    q)(cols `t)~key flip value `t 1b 
    q)ts:10000 cols `t 12 528 
    q)ts:10000 key flip value `t 2 880

    One of the loveliest aspects of working in q is how easy it is to experiment like this!

     

  • Laura

    Administrator
    March 17, 2022 at 12:00 am in reply to: Why do we put a 0# here: @[`.;t;@[;`sym;`g#]0#]

    TLDR: the expression initialises a list t of tables in the default namespace, setting the grouped attribute on the symbol column and removing all the table rows.

    How that? The function called is not Apply but Amend At @ in its ternary form.

    The first argument is the default namespace `., which, as a namespace, is also a dictionary.

    The second argument t will be a symbol vector of names of tables in the default namespace; i.e. globals.

    The third argument is the function to be applied to each table. Youve already spotted that the unary projection @[;`sym;`g#] sets the grouped attribute on the sym column. It is composed (by juxtaposition) with the unary projection 0#. Applied to a table, 0# removes all the rows.

    So the function applied to each table named in t is the composition @[;`sym;`g#] 0#. That is, remove the rows and set grouped on the sym column.

  • Laura

    Administrator
    March 16, 2022 at 12:00 am in reply to: Understanding this line from vanilla tick set up

    Where u, v, w, etc. are unaries then u v w@ is a unary composition equivalent to {u v w x}.

    In this case two of the five unaries are projections. A little spacing clarifies:

     

    (`time`sym~ 2# key flip value@) each t

     

  • Laura

    Administrator
    March 15, 2022 at 12:00 am in reply to: What does w[x;;0] mean in this line:del:{w[x]_:w[x;;0]?y};.z.pc:{del[;x]each t};

    The line consists of two definitions: of del and of .z.pc.

    The former is a lambda that amends the value of an existing value w. We can see from w[x;;0] that w is a list with at least rank 3, i.e. three levels of indexing. Say w is a list in which the items are lists of lists. Then w[x;;0] refers to the first items of the lists in row x.

     

    q)show w:3 cut” “vs”The quick brown fox jumps over the lazy dog.”

    “The” “quick” “brown” “fox” “jumps” “over” “the” “lazy” “dog.”

    q)w[1;;0]

    “fjo”

    q)w[1]_:w[1;;0]?”j”

    q)w (“The”;”quick”;”brown”) (“fox”;”over”) (“the”;”lazy”;”dog.”)

     

    Then w[x;;0]?y finds the first occurrence of y among them. Where is an operator the syntax x:y is equivalent to x:xy, so the w[x]_: drops from row x the first list that begins with y.

  • Laura

    Administrator
    March 15, 2022 at 12:00 am in reply to: Does -2 log messages?

    2 is the permanent connection handle for stderr. See https://code.kx.com/q/basics/handles/

  • Laura

    Administrator
    March 12, 2022 at 12:00 am in reply to: Arguments of .Q.hdpf

    The complete call in the white paper is .Q.hdpf[`$":",.u.x 1;`:.;x;`sym].

    The first argument is `$":",.u.x 1. From the .Q.hdpf documentation we see the first argument is a port for the HDB. It looks like .u.x. 1 is that as a string; for example "localhost:5002".

    `$":", prefixes a colon and casts to symbol, creating a handle.

Page 12 of 16