I've been looking at APL code samples, and some of them use QUAD FI, QUAD VI and QUAD VFI. The first two are described in my textbooks (APL an interactive approach). When I try these in APL2, I get a VALUE ERROR.
Is there a equivalent in APL2?
While I think QUAD FI and QUAD VI are part of MicroAPL's APLX, APL2 (according to the available IBM APL2 manual) appears having no direct support for them.
If you just need to find an implementation that can run your code samples, APLX as a discontinued APL2 compatible product can be download for free at http://www.dyalog.com/aplx.htm
In plain APL2 you could simulate the behavior by split the input string at space, write your own checker for validness (to avoid arbitrary code been executed), and use ⍎
(Execute) to get the value.
A not so correct implementation of QUAD VI can be:
∇r←valide str
⍝ This doesn't test if ¯ sign occurs in the middle
r←∧/str∊'¯0123456789.'
∇
∇r←VI str
r←valide¨(' '≠str)⊂str
∇
VI '100.32 $4 2,,3 0 12.2 ¯3 +2 -2'
1 0 0 1 1 1 0 0
With the QUAD VI in hand we can make QUAD FI by
∇r←FI str;mesh
⍝ again this is very crude on edge cases
r←mesh\⍎¨(mesh←VI str)/(' '≠str)⊂str
∇
(Note the above example won't work in Dyalog APL)
Since the question has a dyalog
tag, Dyalog APL has the QUAD VFI system function, which is simply a composition of the other two. So (⊃⊢⌿)∘⎕VFI
is apparently equal to ⎕FI
and (⊃⊣⌿)∘⎕VFI
is equivalent to ⎕VI
.
Here is a ⎕VI
equivalent which I remember seeing in APL Quote-Quad some time in the 1980s, typed in from memory. The original author was G. Bamberger, I think. As I used APL on the major timesharing companies (Sharp, STSC) and then later worked on IBM VSAPL which had no ⎕VI
, this function proved very useful.
∇ r←vi x;t;b
[1] t←' 11111111112345'[' 1234567890¯E.'⍳x]
[2] b←t='1'
[3] t←(b⍲0,¯1↓b)/t
[4] r←(⍎t,',⍳0')∊1 14 21 41 131 141 214 241 1321 1431 2131 2141 4131 14131 14321 21321 21431 21432 24131 41321 141321 214131 241321 2141321
∇
LdBeth's FI
with a change to make it work for empty vectors is fine.
∇r←fi str;mesh
r←mesh\⍎(⍕(mesh←vi str)/(' '≠str)⊂str),',⍳0'
∇
(I checked this on Dyalog with ⎕ML←3
)
Where vi
can be interesting is in cases where you don't agree with ⎕VI
's default answer.
Suppose you want either high or low minus to be valid, as well as both upper and lower case E for exponential notation:
[1] t←' 1111111111223345'[' 1234567890-¯Ee.'⍳x]
Or if you wanted comma as a decimal separator (as it is in some locales)
[1] t←' 11111111112345'[' 1234567890¯E,'⍳x]
Of if you don't want to support E notation at all
[1] t←' 1111111111234'[' 1234567890¯.'⍳x]
Don't forget to change the magic numbers on line 4 accordingly, an exercise left to the reader. Also to substitute characters accordingly in the companion fi
function.
Lastly, a number of APLs now have complex numbers (1J2
, 1.0E42J1.000042
) and vi would need to be changed accordingly. This vi
does not support complex numbers. Future APLs may include quaternions, octonions, Cayley numbers, all of which would probably require changes to vi
. For casual validation, handling 1
1.0
1.
.1
should be enough.