3

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?

Alexander Belopolsky
  • 2,228
  • 10
  • 26
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91

1 Answers1

2

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"
user1895961
  • 1,176
  • 9
  • 22
  • Why are the results printed vertically in both examples? What are the types produced by each command in your answer? – Robert Kubrick Mar 25 '13 at 19:02
  • " abc" is just a list of 4 character elements. When you join 10:00:00 you are creating a mixed list of 5 elements. `q)count (10:00:00)," abc"` (returns 5). In order to produce 2 list of lists, you would first need to enlist the character string. `q)count l:(10:00:00),enlist " abc"` (returns 2). `q)l` (returns (10:00:00;"abc")) – user1895961 Mar 25 '13 at 19:05
  • ok, so the commas in the second command output indicate different invocations to string(), one for each atom type (and not a list like in the first command result). Am I correct? – Robert Kubrick Mar 25 '13 at 19:16