Roger Smith <ACPS5788@Ryerson.CA> (04/06/91)
Hi I was wondering if someone could send me or post a simple program that would take a matrix on the stack eg [[ 2 3 4 5] or any arbitrary size and return the square of all of the elements [ 3 1 3 4] in the array . It sounds trivial but the manual is not clear on [ 2 3 1 1] this aspect of programming the 48sx, thanks in advance. [ 1 3 3 1]] Roger Smith Ryerson Polytechnic Ont. Canada acps5788@ryerson.bitnet
cloos@acsu.buffalo.edu (James H. Cloos) (04/06/91)
In article <91096.000611ACPS5788@Ryerson.CA> ACPS5788@Ryerson.CA (Roger Smith) writes: >Hi > I was wondering if someone could send me or post a simple program that would >take a matrix on the stack eg [[ 2 3 4 5] or any arbitrary size and return the >square of all of the elements [ 3 1 3 4] in the array . It sounds trivial but >the manual is not clear on [ 2 3 1 1] this aspect of programming the 48sx, >thanks in advance. [ 1 3 3 1]] > Here, try this: %%HP: T(3)A(R)F(.); @ @ Expects an ARRAY in level 2 and a program in level1, and @ applies the program to each element of the array individually. @ The results are unpredictable if the program does not take a @ single argument and return a single result to the stack! @ By Jim Cloos. @ This is hereby put into the public domain. @ \<< OVER SIZE \-> prog dims \<< 1 dims LIST\-> 1 SWAP START * NEXT \-> elems \<< ARRY\-> DROP 1 elems START prog EVAL elems ROLL NEXT \>> dims \->ARRY \>> \>> prog holds the program, dims the list of the arry's dimensions, and elems the total number of elements in the array. This can be done more efficiently, and robustly (especially with the internal system rpl), but the above will at least set you in the right direction. Enjoy, -JimC -- James H. Cloos, Jr. Phone: +1 716 673-1250 cloos@ACSU.Buffalo.EDU Snail: PersonalZipCode: 14048-0772, USA cloos@ub.UUCP Quote: <>