Apl2Idioms/AssignmentAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
⍎(0=⎕NC 'A')/'A←1' ⍝ Assign value to A if not assigned.
⍎(1=≡A)/'A←⊂A' ⍝ Change A to scalar if it is simple.
V←1↓⍎'0 ',V ⍝ Execute which works on empty vector.
V←1↓⍎¨CSV,VV ⍝ Execute each with prototype of CSV.
⍎¨⊂[1]MX,'←',⍕MY ⍝ Assigns MY-values to matrix of MX-names.
⍎¨⊂[2]MX,'←',⍕MY ⍝ Assigns MY-values to matrix of MX-names.
NS←V[(0≠⍴V)?⍴V] ⍝ Select random item from vector. Works on ''. ???
S←(¯1 0 1⍳×NS)⊃SW SX SY ⍝ Selection depending on sign of scalar.
A←PA⊃¨⊂A ⍝ Chipmunk. Selective picking from array.
AV←PAV⊃¨¨⊂⊂A ⍝ Selective multiple subarrays from array.
(,A)[(⍴A)⊥⍉PM]←V ⍝ Scatter assignment. (⍴PM)=(⍴V),⍴⍴A
(,A)[1+(⍴A)⊥⍉¯1+PM]←V ⍝ Scatter assignment. (⍴PM)=(⍴V),⍴⍴A
(PV⌷¨⊂A)←V ⍝ Scatter assignment. (⍴PV)=⍴V. (⍴¨PV)=⍴⍴A
V←PV⌷¨⊂A ⍝ Scatter indexing. (⍴PV)=⍴V. (⍴¨PV)=⍴⍴A
X←'line1',0⍴Y←'line2' ⍝ Pornography. Combining two lines into one.
X←↑'line1' Y←'line2' ⍝ Pornography. Combining two lines into one.
CM←'|',('¯',[0]CM,[0]'_'),'|' ⍝ Framing CM in a box.
CM←'|',('¯',[1]CM,[1]'_'),'|' ⍝ Framing CM in a box.
APL Wiki