12 `56 `˜šš

45`1 `

9 `14 `

`

Select the VAR menu and execute MNX2.

J%MNX2%

Find the minimum element.

%MIN%

Applying a Program to an Array

APLY makes use of list processing to transform each element of an array according to a desired procedure.

The procedure applied to each element must be a program that takes exactly one argument (i.e. the element) and returns exactly one result (i.e. the transformed element).

The procedure assumes flag –55 to be clear, and unexpected results could be returned if flag –55 is set.

Level 2

Level 1

Level 1

 

 

 

 

[ array ]

« program »

[[ array ]] or {{ array }}

 

 

 

 

Techniques used in APLY

Manipulating Meta-Objects.Meta-objectsare composite objects like arrays and lists that have been disassembled on the stack. APLY illustrates several approaches to manipulating the elements and dimensions of such objects.

Application of List Processing. APLY makes use of DOSUBS (although DOLIST might also have been used) to perform the actual transformation of array elements.

Using an IFERR…THEN…ELSE…END Structure. The entire symbolic pseudo-array case is handled within a error structure — triggered when the →ARRY command generates an error when symbolic elements are present.

Using Flags. User flag 1 is used to track the case when the input array is a vector.

APLY program listing

Program:

Comments:

«

 

→ a p

Store the array and program in local variables.

«

Begin the main local variable structure.

 

 

2-20 RPL Programming Examples