Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output difference when calling string()

Tags:

q-lang

kdb+

I want to concatenate a number of variables having different types into a string. This works well:

q)"select ", string[10:00:00] ," abc"
"select 10:00:00 abc"

When I call string with parenthesis the output is different:

q)"select ", string(10:00:00) ," abc"
"s"
"e"
"l"
"e"
"c"
"t"
" "
"10:00:00"
," "
,"a"
,"b"
,"c"

I think in the first example the function string is invoked with an atom parameter of type time, while in the second call a time list is created before invoking string.

What does the output indicate in the second example?

like image 803
Robert Kubrick Avatar asked Jul 27 '26 17:07

Robert Kubrick


1 Answers

With string[10:00:00], you are calling the string function on the input 10:00:00. With string (10:00:00) ," abc" , you are acually joinng (10:00:00) to "abc" and then stringing the results. You have to remember that execution is carried out from right to left.

q)(10:00:00) ," abc"
10:00:00
" "
"a"
"b"
"c"
q)string (10:00:00) ," abc"
"10:00:00"
," "
,"a"
,"b"
,"c"
like image 102
user1895961 Avatar answered Jul 29 '26 19:07

user1895961



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!