I’m trying to write a Q function that generates a permutation matrix (a boolean matrix with only a single 1 in each row and column, zeroes elsewhere). The function below gives me the “assign” error on the first assignment statement inside the do-loop. This should mean that I’m misusing a reserved word, but I don’t see how that could be the case here. Also, as an old APLer, I thought that it should be possible to write this function without an explicit loop, but I can’t figure out how.
permutation:{
j:(neg x)?x;
i:til x;
a:(x;x)#0;
k:0;
do[
x;
a[i[k]][j[k]]:1;
k:k+1;
];:a}