Execute Inverse with quadTF
Vector 20:3, page 36
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 36
Acknowledgement¶
I can’t claim much credit for the attached – it was mainly the work of Allan Gay and as far as I recall my contribution was limited to removing unnecessary parentheses from the result. As you will see, all I have done is write a cover function to call the function that emulates APL2’s ⎕TF.
Example Usage¶
qq←(2 3⍴⍳6)(3 4⍴⍳12)'Hello, world'
iq←EI qq
iq
3⍴(2 3⍴1 2 3 4 5 6)(3 4⍴1 2 3 4 5 6 7 8 9 10 11 12)(12⍴'Hello, world')
⍎iq
1 2 3 1 2 3 4 Hello, world
4 5 6 5 6 7 8
9 10 11 12
⎕vr 'EI'
∇ Z←EI Y
[1] Z←2↓2 quadTF 'Y'
∇
Listings (for extended transfer form only)¶
∇ ΔZ←ΔA quadTF ΔW;⎕IO
[1] ⍝ Limited simulation of APL2's ⎕TF for APL*PlusII/386.
[2] ⍝ (System ⎕ functions and variables are not supported).
[3] ⍝ ⍺ is integer scalar or 1-integer vector:
[4] ⍝ 1 declares migration transfer form
[5] ⍝ 2 declares extended transfer form.
[6] ⍝ ⍵ is character scalar or vector, which is one of:
[7] ⍝ i) the name of an APL item to represent
[8] ⍝ ii) the representation of an APL item to be reconstituted.
[9] ⍝ ← is character vector containing, for the two cases of ⍵:
[10] ⍝ i) an ⍺-type representation of the item named in ⍵
[11] ⍝ ii) the name of the item reconstituted from ⍵.
[12]
[13] ⎕ERROR (~ΔA ∊ 1 2)/'DOMAIN ERROR' ⍝ ⍺ must be 1 or 2.
[14] ⎕ERROR ((ΔA∊1)∧1<≡ΔW)/'DOMAIN ERROR' ⍝ ⍵ must be simple when ⍺ is 1.
[15] ⎕ERROR (' '≠⎕TYPE ↑ΔW)/'DOMAIN ERROR' ⍝ ⍵ must be text.
[16] ⎕ERROR (0∊⍴,ΔW)/'DOMAIN ERROR' ⍝ ⍵ must not be empty.
[17]
[18] →(' '∊ΔW)/RRR ⍝ Go reconstitute from ⍵.
[19]
[20] →(AAA,BBB)[ΔA]
[21] AAA: ⍝ MAKE MIGRATION TRANSFER FORM:
[22] ΔZ←quadTF_out1 ΔW ⍝ Make representation.
[23] ⎕ERROR (¯1≡ΔZ)/'DOMAIN ERROR' ⍝ Mixed datatypes unsupported.
[24] →ZZZ
[25] BBB: ⍝ MAKE EXTENDED TRANSFER FORM:
[26] ΔZ←quadTF_out2 ΔW ⍝ Make representation.
[27] →ZZZ
[28]
[29] RRR:
[30] →(TTT,UUU)[ΔA]
[31] TTT: ⍝ USE MIGRATION TRANSFER FORM:
[32] ΔZ←quadTF_in1 ΔW ⍝ Reconstitute APL object.
[33] →ZZZ
[34] UUU: ⍝ USE EXTENDED TRANSFER FORM:
[35] ΔZ←quadTF_in2 ΔW ⍝ Reconstitute APL object.
[36] →ZZZ
[37]
[38] ZZZ:
∇
∇ Δz←quadTF_out2 Δw;ΔV;⎕IO
[1] ⍝ Represent APL object named ⍵ in extended transfer form
[2] ⍝ ⍵ is character scalar or vector name of an APL item to represent.
[3] ⍝ ← is character vector ⍺-type representation of the item named in ⍵.
[4]
[5] ⎕IO←1
[6]
[7] Δz←'' ⍝ Default result.
[8] →(~(⎕NC Δw)∊2 3)/ZZZ ⍝ Ignore unsupported classes.
[9] →(3=⎕NC Δw)/XXX ⍝ Go represent fn ⍵.
[10]
[11] ΔV←⍎Δw ⍝ Determine array type:
[12] →(1<≡ΔV)/NNN ⍝ . go do nested array.
[13] →(1<+/0 1∊∊0=1↑¨0⍴¨ΔV)/MMM ⍝ . go do mixed array.
[14] →SSS ⍝ . go do simple array.
[15]
[16] MMM: Δz←quadTF_out2_mixed ΔV ⋄ →VVV ⍝ Represent mixed array.
[17] NNN: Δz←quadTF_out2_nested ΔV ⋄ →VVV ⍝ Represent nested array.
[18] SSS: Δz←quadTF_out2_simple ΔV ⋄ →VVV ⍝ Represent simple array.
[19]
[20] VVV:
[21] →(1≥≡ΔV)/WWW
[22] Δz←1↓¯1↓Δz ⍝ Drop superfluous parentheses
[23] WWW:
[24] Δz←Δw,'←',Δz,' ' ⋄ →ZZZ ⍝ Make an assignment statement.
[25]
[26]
[27] XXX: ⍝ REPRESENT FUNCTION ⍵:
[28] Δz←,'⍠',⎕CR Δw ⍝ Get the ⎕CR and double all
[29] Δz←(1+Δz∊'''')/Δz ⍝ quotes first.
[30] Δz←DLTB ¨⎕SPLIT SStoMAT Δz ⍝ Convert to vectors, omitting
[31] Δz←'⎕FX disclose', ⍕'''',¨Δz,¨'''' ⍝ leading/trailing blanks.
[32] →ZZZ
[33]
[34] ZZZ:
∇
∇ Δz←quadTF_out2_mixed Δw
[1] ⍝ Represent simple mixed APL array ⍵
[2] ⍝ in extended transfer form.
[3] ⍝ ⍵ is the mixed array
[4] ⍝ ← is text vector representation of the named array
[5]
[6] Δz←(1,¯1↓(Δw∊⎕AV)≠1↓(Δw∊⎕AV),0) ⎕PENCLOSE ,Δw
[7] Δz← 1↓∊ ',' ,¨ quadTF_out2_enquote ¨Δz
[8] Δz←(⍕⍴Δw),'⍴',Δz,' '
∇
∇ Δz←Δa quadTF_out2_nested Δw;ΔS;ΔX;⎕IO
[1] ⍝ Represent nested APL array ⍵
[2] ⍝ in extended transfer form.
[3] ⍝ ⍺ is 1 if parent array was scalar, else 0
[4] ⍝ ⍵ is the array
[5] ⍝ ← is character vector representation of ⍵ content
[6]
[7] ⎕IO←1
[8] ⍎(0=⎕NC 'Δa')/'Δa←0'
[9]
[10] →(ΔX←0=⍴ΔS←⍴Δw)/AAA ⍝ Note if ⍵ scalar.
[11] →(~0∊ΔS)/AAA ⍝ Go do non-empty
[12] ΔΔz←⊂⎕TYPE ↑Δw ⍝ Approximation when empty
[13] Δz←4↓2 quadTF 'ΔΔz'
[14] →OOO
[15]
[16] AAA:
[17] →(1<≡Δw)/NNN ⍝ Go do nested array.
[18] →(1<+/0 1∊∊0=⎕TYPE¨Δw)/MMM ⍝ Go do mixed array.
[19] →SSS ⍝ Go do simple array.
[20]
[21] NNN:
[22] Δz←∊(⊂ΔX)quadTF_out2_nested ¨Δw ⍝ Represent nested array.
[23] OOO:
[24] Δz←((~ΔX)/(⍕ΔS),'⍴'),Δz ⍝ Make a representation.
[25] →WWW
[26]
[27] MMM: Δz←quadTF_out2_mixed Δw ⋄ →WWW ⍝ Represent mixed array.
[28]
[29] SSS: Δz←quadTF_out2_simple Δw ⋄ →WWW ⍝ Represent simple array.
[30]
[31] WWW:
[32] →Δa↓XXX
[33] Δz←'⊂',Δz ⍝ Enclose if parent scalar
[34] XXX:→ΔX/YYY
[35] Δz←'(',Δz,')' ⍝ Parenthesise result.
[36] →ZZZ
[37] YYY: Δz←Δz,(')'≠¯1↑Δz)/' '
[38]
[39] ZZZ:
∇
∇ Δz←quadTF_out2_simple Δw
[1] ⍝ Represent simple unmixed APL array named ⍵
[2] ⍝ in extended transfer form.
[3] ⍝ ⍵ is the simple array
[4] ⍝ ← is text vector representation of ⍵ content
[5]
[6] Δz←quadTF_out2_enquote Δw ⍝ Add/double quotes as needed
[7] →(0=⍴⍴Δw)/ZZZ ⍝ If nonscalar,
[8] Δz←((⍕⍴Δw),'⍴'),Δz ⍝ apply shape.
[9]
[10] ZZZ:
∇
∇ Δz←quadTF_out2_enquote Δw
[1] ⍝ Represent simple unmixed APL array ⍵ as text.
[2] ⍝ If ⍵ is text, enquote it and double all embedded quotes.
[3] ⍝ ⍵ is the array
[4] ⍝ ← is character vector representation of ⍵ content
[5]
[6] Δz←⍕(,Δw),((0=⎕TYPE↑Δw)∧0∊⍴Δw)/0 ⍝ If ⍵ is not text,
[7] →(' '≠⎕TYPE ↑Δw)/ZZZ ⍝ no quotes are needed.
[8] Δz←(1+Δz∊'''')/Δz ⍝ Double any single quotes
[9] Δz←'''',Δz,'''' ⍝ Enquote the result.
[10]
[11] ZZZ:
∇
∇ ΔZ←quadTF_in2 ΔW;ΔN;ΔQ;ΔR;ΔS;⎕IO
[1] ⍝ Reconstitute an APL object from extended transfer form in ⍵
[2] ⍝ ⍵ is character vector representation of an APL object.
[3] ⍝ ← is character vector name of reconstituted object.
[4]
[5] ⎕IO←1
[6]
[7] →('⎕FX'∧.=3↑ΔW)/PPP ⍝ Go handle fn.
[8] ΔZ←(¯1+ΔW⍳'←')↑ΔW ⍝ Get name to reconstitute.
[9] ⍎ΔW ⍝ Reconstitute the var.
[10] →ZZZ
[11] PPP:
[12] ⍎'ΔZ←',ΔW ⍝ Reconstitute a fn.
[13] →ZZZ
[14]
[15] ZZZ:
∇