KX Community

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

Home Forums kdb+ kdb+/q Developer Lv2 – list indexing : exercise GList just before 4.2 for type

  • kdb+/q Developer Lv2 – list indexing : exercise GList just before 4.2 for type

    Posted by Ken__ on June 2, 2025 at 1:54 am

    Q1: why the type each GList not give -11h -7h -10h instead of -11 -7 -10h with only 3rd element with h for short value?


    Q2: the ipynb notebook seems to give results not following the command order,

    shouldn’t it be below if it respects the command query order?


    my query and expected results:

    type `a

    type 1

    type “b”

    -11h
    -7h
    -10h

    while the offical query and results look -11 -7 -10h so -11 is long -7 is long? or shorthand it is all short for h but just show for the last 3rd element?

    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    • This discussion was modified 3 days, 18 hours ago by  Ken__.
    megan_mcp replied 1 day, 9 hours ago 2 Members · 3 Replies
  • 3 Replies
  • megan_mcp

    Administrator
    June 3, 2025 at 3:05 pm

    Hi @Ken__ 

    1. The h at the end of the list isn’t related to the last value. The h is placed at the end of the list to indicate this is a list of data type values.

    2. Do you mean why are the results showing the types before displaying the list even though the “show” query comes before the “type” query?

    • Ken__

      Member
      June 3, 2025 at 7:31 pm

      1. thanks prompt reply, but it’s a bit confusing indeed, so after your explanation it’s for the WHOLE LIST of same type value h, the type each in type each GList: (`a; 1 ; “b”) shows a list of value of each element data type and then an “h” char at the last to show these values of data type are of short type only.  <span style=”background-color: transparent; font-family: inherit; font-size: inherit;”>I thought as if it would show the same as the individual type command i.e.type `a

      type 1

      type “b” 

      will get same expected results from type each (`a;1;”b”) but it does not. 

      quite the opposite to what I thought would give the same result to individual type query to 3 value. I still cannot convey myself and dry run in brain when and why “type each” would show like this. 

      I can only think of a reasonable answer – type each would generate a list of same value, in this case it must be “h” for short

      2. yes your understanding to the question is correct, 

      the juypter notebook gives results of 

      type each GList first, 

      and then 

      show GList value

      however the command on notebook is 

      show GList and 2nd line the 

      type each GList

      why is that?

      • megan_mcp

        Administrator
        June 4, 2025 at 10:46 am

        Hi @Ken__ 

        1. When running the type function, it will return the type code (an integer) indicating the data type of the value. The h represents that it is returning a short type code.

        Whether we run it individually on each item e.g.

        type `a
        type 1	
        type "b"
        
        
        Output:
        -11h  //short type code for symbol
        -7h   //short type code for int
        -10h  //short type code for char
        

        Or in one go over a list:

        type each GList	
        
        Output:
        -11 -7 -10h   //short type codes for symbol, int, char

        The “h” at the end indicates that it is displaying the short type code for those items.

        2. I believe the output format is due to Jupyter’s output model. Commands such as show x prints the result of evaluating x, but does not return a valueJupyter cells only display the value of the last expression, and show returns nothing (:: or null), the output is printed directly as a side effect, not as a result.

        For example, running show L will output the query last but outputting L as a variable will run before the second query (screenshots provided below)

        I hope this helps!

Log in to reply.