Up | Next | Prev | PrevTail | Tail |
Normally, procedures can only return scalar values. In order for a procedure to return a matrix, it has to be declared of type matrixproc:
matrixproc SkewSym1 (w); mat((0,-w(3,1),w(2,1)), (w(3,1),0,-w(1,1)), (-w(2,1), w(1,1), 0));
Following this declaration, the call to SkewSym1 can be used as a matrix, e.g.
X := SkewSym1(mat((qx),(qy),(qz))); [ 0 - qz qy ] [ ] x := [ qz 0 - qx] [ ] [ - qy qx 0 ] X * mat((rx),(ry),(rz)); [ qy*rz - qz*ry ] [ ] [ - qx*rz + qz*rx] [ ] [ qx*ry - qy*rx ]
Similarly, by using the keyword listproc, an algebraic procedure can be declared to return a list. For example, the following procedure returns a normalized version of the vector provided as its argument, represented as a list (i.e. the returned vector has unit Euclidean norm):
listproc normalize v; begin scalar n := sqrt for each vi in v sum vi^2; return for each vi in v collect vi/n end;
(Note that the LISTVECOPS package provides elegant vector operations on lists, which allow the above procedure to be written much more succinctly; see the version at the end of the LISTVECOPS section.)
Up | Next | Prev | PrevTail | Front |