2022.04.01 08:01 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.
2022.04.01 08:36 AM
This behaviour happens with file handles also:
Applying the handle to data appends it to the file as bytes.
Applying theneg
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'
helloq)
q)-1"hello"; //-1 is often more useful as it includes a \n newline char
hello
2022.04.05 04:51 AM
To enlarge on Rian’s 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)
2022.04.01 08:36 AM
This behaviour happens with file handles also:
Applying the handle to data appends it to the file as bytes.
Applying theneg
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'
helloq)
q)-1"hello"; //-1 is often more useful as it includes a \n newline char
hello
2022.04.05 04:51 AM
To enlarge on Rian’s 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)
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.