KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Issues with Outputs of Strings and Symbols

  • Issues with Outputs of Strings and Symbols

    Posted by mn_12 on May 3, 2023 at 12:00 am

    Hi,

     

    I intended to write this as well in my previous post but decided to do so in a new post here as it concerns another subject.

     

    While I was working through both the Tables and Tables Exercises notebooks, I noticed some peculiarities with the outputs of strings and symbols in the console whenever lists are involved. In some instances, the ` for a symbol and the ” ” for a string do not appear but in others, they do.

     

    1.

     

    (`a`g;1 2) results in

    a g 
    1 2

    and (“ag”;1 2) also results in

    a g 
    1 2

    However, flip (`a`g;1 2) results in

    `a 1 
    `g 2

    and flip (“ag”;1 2) results in

    "a" 1 
    "g" 2
    I am uncertain and wondering if there is a way to have a `  for each of a and g in the output of (`a`g;1 2)  and a ” ” for each of a and g in the output of (“ag”;1 2).
    2.
    I am also uncertain and wondering if there is any rule as to when the ` for a symbol and the ” ” for a string will appear whenever lists are involved. Based on all my observations in 1. as well as below, my guess is that it has something to do with a general list, the number of items of all the lists in the general list being the same, the general list having more than one list and the general list having at least a list of symbols. In such an instance, the ` for a symbol and the ” ” for a string will not appear. However, I am uncertain if I am right as I am still new to q/kdb+.
    ` do not appear but ” ” appear:

    enlist `a`g results in

    a g
    but enlist “ag” results in
    "ag"

     

    (`a`g;`b`h)  results in

    a g 
    b h

    but (“ag”;”bh”)  results in

    "ag" 
    "bh"

     

    ` and ” ” appear:

     

    (`a`g;(),1) results in

    `a`g 
    ,1

    and (“ag”;(),1) results in

    "ag" 
    ,1

     

    ` appear:

     

    (),`MSFT results in

    ,`MSFT

    and (),`T results in

    ,`T

     

    (`MSFT;`T) results in

    `MSFT`T

     

    ` do not appear:

     

    However, ((),`MSFT;(),`T) results in

    MSFT 
    T

     

    Once again, I really appreciate any help with these issues.

     

    Thank you very much.

    mn_12 replied 8 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • rocuinneagain

    Member
    May 3, 2023 at 12:00 am

    q makes a balance when displaying about levels of detail.

    Always giving full exact information would make all output very messy and more like code rather than nicely displayed information for human to view.

     

    There are some tools and tips you can use to inspect items in more detail during development and debugging.

    Using .Q.s1 is most useful I find to drill down. (Along with usual type, count etc)

    https://code.kx.com/q/ref/dotq/#s1-string-representation

     

     

    -1 .Q.s1 itemToInspect

     

     

     

    A script designed to display items in detail nicely:

    https://github.com/LeslieGoldsmith/dpy

     

Log in to reply.