cancel
Showing results for 
Search instead for 
Did you mean: 

Why sometimes the amend/index doesn't work?

vivo
New Contributor II

In below code, a1 doesn't work. Any ideas why?

 

myObj: (5 7; (`a; `b ; (4 5)));

a3:.[myObj; 1 2 1; {count x}]; // i.e. ((5 7);(`a;`b;4 1))
a2:.[myObj; 1 2; {count x}]; // i.e. ((5 7);(`a;`b;2))
a1:.[myObj; 1; {count x}]; // i.e. it doesn't work
a0:.[myObj; (); {count x}]; // i.e. 2

 

1 ACCEPTED SOLUTION

gyorokpeter-kx
New Contributor III
New Contributor III

It's because the dot operator always requires a list as the index. 1 2 1, 1 2 and () are lists, 1 is not. It works if you enlist it.

a1:.[myObj; enlist 1; {count x}];

View solution in original post

1 REPLY 1

gyorokpeter-kx
New Contributor III
New Contributor III

It's because the dot operator always requires a list as the index. 1 2 1, 1 2 and () are lists, 1 is not. It works if you enlist it.

a1:.[myObj; enlist 1; {count x}];