KX Community

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

Home Forums KX Academy 1 "hello" return hello1

  • 1 "hello" return hello1

    Posted by mannix on April 1, 2022 at 12:00 am

    Why does:
    q)1\”hello”\

    hello1

    I have checked that: 2 “hello” returns hello2.

    I know that 1 and 2 are permanent handles to stdout and stderr, but I’m not sure why the handles would be returned after the string.

    mannix replied 8 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    April 1, 2022 at 12:00 am

    This behaviour happens with file handles also:

    Applying the handle to data appends it to the file as bytes.
    Applying the neg of the handle to char data appends it as text. The result of a successful operation is the positive or negative handle.

    File system | Basics | kdb+ and q documentation – Kdb+ and q documentation (kx.com)

    As to why I am not sure. The choice could have been made to return a generic null (::) instead possibly.

     

    For stdout and stderr it can feel strange at first but it is not printing ‘hello1’ in one go. Instead ‘hello’ is printed as you requested then as you are in an interactive session the q) prompt wants to display the returned object so it then prints ‘1’.

    q)1"hello"; //The ; stops the q) prompt from printing the returned object '1' hello
    q)
    q)-1"hello"; //-1 is often more useful as it includes a n newline char hello

     

  • Laura

    Administrator
    April 5, 2022 at 12:00 am

    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)

     

     

Log in to reply.