-
Henrik Wallin authored
Rev: about_pike/perl_tcl_python_pike:1.2
Henrik Wallin authoredRev: about_pike/perl_tcl_python_pike:1.2
perl_tcl_python_pike 1015 B
This file is just here to give an example of how Pike-code look. It's
not a try to show how great Pike is or an example of how Pike should
be coded.
If you want to compare with Perl, Tcl och Python have a look at:
http://www.unixworld.com/unixworld/archives/95/tutorial/005.html#Others
Here is a Pike-function that multiplies two matrixes:
(Note: This is best done in Pike using matrix objects with a
`*-method. This is just made for comparison with the examples in the
URL.)
#define matrix array(array(int|float|object))
matrix mmult(matrix m1, matrix m2)
{
int m2rows=sizeof(m2), m2cols=sizeof(m2[0]);
int m1rows=sizeof(m1), m1cols=sizeof(m1[0]);
if ((m1cols!=m2rows)||(m2cols!=m1rows))
return 0;
matrix res=allocate(m1rows);
for(int i; i<m1rows; i++)
res[i]=allocate(m2cols);
for(int i; i<m1rows; i++)
for(int j; j<m2cols; j++)
res[i][j]=`+(@ Array.sum_arrays(`*, m1[i], column(m2, j)));
return res;
}
//
och the Pike-part is written by Henrik "Hedda" Wallin, Idonex.