Naming Conventions

Scalar

Vector

Matrix

Any
rank

Non-
scalar

Boolean

BS

BV

BM

BA

BN

Integer

IS

IV

IM

IA

IN

Float

FS

FV

FM

FA

FN

Numeric

NS

NV

NM

NA

NN

Character

CS

CV

CM

CA

CN

Enclosed
vector

ES

EV

EM

EA

EN

enclosed
Text vector

TS

TV

TM

TA

TN

Simple

SS

SV

SM

SA

SN

Any

AS

AV

AM

AA

AN

phrase e.g.: .X...Y. ⍝ X←BS; Y←IV

combinations: use ISV for Integer scalarvector

B3, I4 &c. to specify higher ranks.

Open full technical reference

ForLoop

/!\ Page under construction

To code a for-loop (see pseudo-code below) in which y is the primary argument to the loop and each iteration runs dyadic function f between y and item x of vector v of data items (a b c d ...) in the given order. At each iteration f is to return a modification of y or another array in the same domain as y as input to the next iteration or finally as the result:

   FOR x IN a b c d ...
      y←x f y
   END

Here it is:

      ⊃f/(⌽V),⊂Y                  ⍝ V←AV; Y←AA

That's it. It's what reduction is.

Examples

      ⎕FX⍕2 1⍴'r←av(f ForLoop)aa' 'r←⊃f/(⌽av),⊂aa'
      2 ¯2 1↓ForLoop 'lose' 'these' 'and this' 'keep' 'these' 'three' 'forget' 'these'
 keep  these  three
      (⍳4)+ForLoop 2 5⍴⍳10
 6  7  8  9 10
11 12 13 14 15
      ⎕fx⍕2 1⍴'r←tv rep cv' 'r←((1⊃tv),cv)[(cv≠0⊃tv)×1+⍳⍴⎕←cv]'
      'ts' rep 'heart'
heart
hears
      'ts' 'hf' 'rt' 'ei' 'as' rep ForLoop 'heart'
heart
hears
fears
feats
fiats
fists

Specialities

Some APLs include control structures specifically to emulate the pseudo-code above. This can offer optimisation opportunities for the interpreter; it also allows the APL editor to indent code for clarity, and to check for unbalanced control structures. However, opinion is divided within the APL programming community about which approach is preferable.

Compatibility

Checked with: APL2, APLX, Dyalog, NARS2000

Test Cases

Show test cases

Test
 ⎕IO←0      ⍝ You may change this; however, zero IS the default in the Phrasebook
⍝⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
 ⎕FX'r←[larg] PhraseName rarg' 'r←phrase'
⍝ ---- Start Test cases (do not delete this!)
 /* expectedResult ≡ statement */

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: ...

Mentor: JohnDoe

Tags: <AppropriateCamelCaseName> <Simpleword>


CategoryPhrasesAll

Phrasebook/ForLoop (last edited 2011-12-26 10:36:25 by KaiJaeger)