1 "hello" return hello1

https://learninghub.kx.com/forums/topic/1-hello-return-hello1-2

Why does:
q)1"hello"</span>

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.

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

 

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)