سؤال

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?

هل كانت مفيدة؟

المحلول

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"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top