Apl2ToDoFunctionAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
A0←⎕IO+A ⍝ A1=A+1 A0=A ⍝ Change ⎕IO dependant argument.
A1←A+⎕IO-1 ⍝ A1=A A0=A-1 ⍝ Change ⎕IO dependant argument.
A0←-⎕IO-A ⍝ A1=A-1 A0=A ⍝ Change ⎕IO dependant result.
A1←A+~⎕IO ⍝ A1=A A0=A+1 ⍝ Change ⎕IO dependant result.
((~,^\('⍝'≠CM)∨≠\CM='''')/,CM)←' '⍝ Decommenting the ⎕CR of a function.
PFK←12+¯12|PFK ⍝ Keep PFK within range 1-12.
VV←(⊂[1]⎕NL 3 4)~¨' ' ⍝ List of functions and operators without ' '.
VV←(⊂[2]⎕NL 3 4)~¨' ' ⍝ List of functions and operators without ' '.
M←,['']⎕CR¨⊂[1]⎕NL 3 4 ⍝ Quick list of all functions and operators.
M←,['']⎕CR¨⊂[2]⎕NL 3 4 ⍝ Quick list of all functions and operators.
IS←+/↑¨⍴¨⎕CR¨⊂[1]⎕NL 3 4 ⍝ The number of code lines in a workspace.
IS←+/↑¨⍴¨⎕CR¨⊂[2]⎕NL 3 4 ⍝ The number of code lines in a workspace.
IS←(+/↑¨⍴¨⎕CR¨⊂[1]M)÷↑⍴M←⎕NL 3 4 ⍝ The average # of lines per pgm. in a WS.
IS←(+/↑¨⍴¨⎕CR¨⊂[2]M)÷↑⍴M←⎕NL 3 4 ⍝ The average # of lines per pgm. in a WS.
CM←(1ε¨(⊂C)⍷¨⎕CR¨⊂[1]CM)⌿CM←⎕NL 3⍝ Find functions that contain string C.
CM←(1ε¨(⊂C)⍷¨⎕CR¨⊂[2]CM)⌿CM←⎕NL 3⍝ Find functions that contain string C.
IS←↑⍴⎕NL 2 3 4 ⍝ The number of objects in a workspace. APL2-specific */
→B/I ⍝ Branch to line in I of first true B.
→PS⊃I ⍝ Branch to line in position PS of I.
IS:→(100<NS←NS+1)/IS ⍝ Branch to label on condition.
→IS+0~B ⍝ IF. Branch on condition B.
→IS×1~B ⍝ IF NOT. Branch if condition B false.
→⎕LC+IS ⍝ Branch to offset IS from current line.
→0 ⍝ RETURN. Leave function, return to caller.
→ ⍝ EXIT. Leave all levels of program.
A←⍎PS⊃VV ⍝ Execute statement PS in VV of statements.
A←⍎↑BS↓'else part' 'then part' ⍝ If Then/Else.
V←⎕FX(⊂C),2 ⎕TF¨⊂[1]⎕NL 2 ⍝ Create a function C to recreate all vars.
V←⎕FX(⊂C),2 ⎕TF¨⊂[2]⎕NL 2 ⍝ Create a function C to recreate all vars.
M←¯1⌽¯1⊖↑∨/O⍷¨⊂M ⍝ Life: next generation given O<=>140 3x3 wins.
((,B)/,A)←fn(,B)/,A ⍝ WHERE. Execute "fn" on condition B mask.
fn¨BS/⊂A ⍝ Conditional execution of monadic function.
⍎'Z←X lo ',((1<≡Y)/'PR¨'),'Y' ⍝ Z←X(lo PR)Y. Perform "lo" as scalar.
Z←X lo↑Y ⎕IO←B ⍝ Z←X(lo IO B)Y;⎕IO. Run "lo" in origin B.
Z←⊃[I](⊂[I]AX)lo⊂AY ⍝ Z←AX(lo OAX I)AY. Run "lo" on axes I of AX.
Z←⊃[I](⊂AX)lo⊂[I]AY ⍝ Z←AX(lo OAY I)AY. Run "lo" on axes I of AY.
APL Wiki