creating a diagonal matrix



Hi,

Sorry if I have missed a FAQ, but is there is a function in Maxima
which allows (non-interactive) construction of a diagonal matrix with
arbitrary values down the diagonal? I have settled on the following
for the moment (comments welcome):

diag(d) := block([n], n : length(d), genmatrix(lambda([i, j],
                          if i = j then d[i] else 0),
                              n, n))

Thanks much.

David
P.S.: On the subject of Maxima-relevant textbooks, I have found
"Macsyma for statisticians" by Barbara Heller (QA276.4 H45 1991)
helpful.