Revised 'MOP' (Matrix OPeration): A function, which executes any algebraic operation or program on every element of an 1 or 2 dimensional array. The improvement is a better error-trapping. My last mail had an error in the examples: I used the name PMEM instead of MOP. I hope, this will be the last correction :-) By the way: I want to know how usefull is this programm to others. If you use this prg, please send me a short "I use MOP"-mail (Also every kind of improvements, questions etc). MOP ! LENGTH = 365 bytes << -> a o << ! store array and operation in local variables DEPTH DUPN ! double stack DEPTH 2 / ->LIST ! copy stack into a list a IFERR RCL ! if array is a name (stored in an object) SWAP OVER a 3 ->LIST ! then add name and contence of object to the list THEN + a a ROT END ! else add array to the list -> b << ! store list (backup in case of an error) 1 SWAP SIZE LIST-> ! size of array IF 1 - THEN * END ! if it is a 2-dim array then multiply size of ! row and column IFERR ! start errortrapping for forbidden operation FOR i ! loop for do the operation on every element IF a TYPE 6 == ! if array is a name (stored in an object) THEN a END ! put array-name in stack i OVER i GET ! get next array-element 'X' STO ! store it o EVAL ! do the operation on that element IFERR ! if result is a complex number and array PUT THEN ! contains only real numbers (==>error) ROT (1,0) * ! convert array into a complex array ROT ROT PUT ! and store the modified element once again END NEXT THEN ! if there was a forbidden operation (like INV(0)) CLEAR ! delete data-garbage (from the error) b LIST-> DROP ! recall backup IF a TYPE 6 == THEN STO ! if array was a name then restore it LIST-> DROP END ! and recall old stack "MOP Error: ! text for error-display " ! important line feed !! ERRM + 1 DISP ! add error-message and show it END 'X' PURGE ! delete no more longer used variable >> >> >> usage: ====== 2: 1: or MOP 2: 1: or MOP 1: 'MOP(,)' EVAL e.g.: ===== 2: [[ 1 2.3 ] [ -3 4.4 [ 1 -1.1 ]] 1: 'LOG(SQR(X))-3' MOP 2: [[ 1 2.3 ] [ -3 4.4 [ 1 -1.1 ]] 1: << IF X 1 < THEN X DUP R->C ELSE X END >> MOP 2: '&DAT' 1: 'INV(X)' MOP 2: '&DAT' 1: << X INV >> MOP 1: 'MOP(MA,X^INV(3))' EVAL ! The algebraic operation must have X as argument. I know, this sucks, but ! calling by reference like 'MOP(INV()*3-2)' is not possible (or ! does anybody know a way ??) ! & := the Sigma-sign (SHIFT V) //////////////////////////////////////////////////////////////////////////// A second, tiny version of MOP, in which the array must be directly in the stack; only call by value is possible (like in example 1 above): MOP ! LENGTH = 260.5 bytes << -> a o << ! store array and operation in local variables DEPTH DUPN ! double stack DEPTH 2 / ->LIST ! copy stack into a list a + ! add array to the list -> b << ! store list (backup in case of an error) a 1 SWAP SIZE LIST-> ! size of array IF 1 - THEN * END ! if it is a 2-dim array then multiply size of ! row and column IFERR ! start errortrapping for forbidden operation FOR i ! loop for do the operation on every element IF a TYPE 6 == ! if array is a name (stored in an object) THEN a END ! put array-name in stack i OVER i GET ! get next array-element 'X' STO ! store it o EVAL ! do the operation on that element IFERR ! if result is a complex number and array PUT THEN ! contains only real numbers (==>error) ROT (1,0) * ! convert array into a complex array ROT ROT PUT ! and store the modified element once again END NEXT THEN ! if there was a forbidden operation (like INV(0)) CLEAR ! delete data-garbage (from the error) b LIST-> DROP ! recall backup "MOP Error: ! text for error-display " ! important line feed !! ERRM + 1 DISP ! add error-message and show it END 'X' PURGE ! delete no more longer used variable >> >> >> The name 'MOP' was created by Schrulli B. thanx ;-) +------------------------------------------------------------------+ ! true name: Ulli Horlacher * e-mail: framstag@dtupev5a.bitnet ! ! nick name: Framstag * s_horlac@dulruu51.bitnet ! ! or Fraturday * 50177::s_horlacher ! ! * snail-mail: Ulli Horlacher ! ! * Landfriedbuehl 5 ! ! Universitaet Ulm * D-7900 Ulm ! ! West-Germany * West-Germany ! !******************************************************************! ! "Murphy was an optimist" ! +------------------------------------------------------------------+