KX Community

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

Home Forums kdb+ Retrieving values from a dictionary using namespacing

  • Retrieving values from a dictionary using namespacing

    Posted by eohara_kdb on June 26, 2023 at 12:00 am

    Hi all,

     

    I would like to understand the following behaviour:

    If the dictionary values are all atoms of the same type, treating the dictionary as a namespace will throw an error when retrieving a value. Otherwise it seems to work ok.

     

    q)dict:`FAWF`faw`erses`gdgr`gr!til 5 
    q)dict 
    FAWF | 0 
    faw  | 1 
    erses| 2 
    gdgr | 3 
    gr   | 4 
    
    q)dict.gr 
    'gr [0] 
    dict.gr ^ 
    
    q)dict:`FAWF`faw`erses`gdgr`gr!(2;44i;54.7;`fs;"ff") 
    q)dict 
    FAWF | 2 
    faw  | 44i 
    erses| 54.7 
    gdgr | `fs 
    gr   | "ff" 
    
    q)dict.gr 
    "ff" 
    q)dict:`FAWF`faw`erses`gdgr`gr!enlist each til 5 
    q)dict 
    FAWF | 0 
    faw  | 1 
    erses| 2 
    gdgr | 3 
    gr   | 4 
    
    q)dict.gr 
    ,4

    Thanks,

    Eoghan

    eohara_kdb replied 8 months, 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • gyorokpeter-kx

    Member
    June 26, 2023 at 12:00 am

    Probably because this syntax is only intended to use with regular namespaces (whose names begin with a dot). When you create a namespace it always has a mixed list in its values because a  ` | :: item is implicitly inserted into it. So the lookup code might be written with the assumption that this always needs to be the case.

Log in to reply.