Size: 2460
Comment:
|
← Revision 8 as of 2010-09-09 23:53:13 ⇥
Size: 2421
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
== Some useful operators == A useful collection of utility functions and operators, [[http://www.dyalog.com/dfnsdws/n_contents.htm|dfns.dws]], is of use only to users of ''DyalogAPL'' as they are all written in the functional subset, ''d-fns'' or ''direct functions'', currently implemented only there. The present author has decided to translate some of the more useful of the operators into standard, ''APL2'' compatible, APL. This will necessarily exclude '''control structures''', not implemented in ''APL2'', as well as the '''guard''' control that characterises ''d-fns''. This leaves only two choices for function flow control. `Labels:` and branches `→` or the use of some of the members of the collection whose sole purpose is precisely to provide flow control without branching. |
= Some useful operators = == dfns.dws == This useful collection of utility functions and operators, [[http://www.dyalog.com/dfnsdws/n_contents.htm|dfns.dws]], is of use only to users of ''DyalogAPL'' as they are all written in the functional subset, ''d-fns'' or ''direct functions'', currently implemented only there. == A translation == The present author has decided to translate some of the more useful of the operators into standard, ''APL2'' compatible, APL. This will necessarily exclude '''control structures''', not implemented in ''APL2'', as well as the '''guard''' control that characterises ''d-fns''. This leaves only two choices for function flow control. `Labels:` and branches `→` or the use of some of the members of the collection whose sole purpose is precisely to provide flow control without branching. The latter is his choice. |
Line 12: | Line 13: |
}}}Ok, here's the problem. We've already called three other things, `dex`, `join` & `lev`, we don't know about so without further ado we'll define them as well.{{{ ∇ r←a dex w r←w |
}}}Ok, here's the problem. We've already called three other things, `dex`, `join` & `lev`, we know nothing about so without further ado we'll define them as well.{{{ ∇ r←a dex r |
Line 17: | Line 17: |
0 0⍴⎕FX 1 5⍴'r←a r' r←a f g w |
0 0⍴⎕FX,⊂'r←a r' r←a f g w |
Line 21: | Line 21: |
0 0⍴⎕FX 1 5⍴'r←a r' r←a dex swap w ∇}}}and the problems multiply themselves because now we need `swap` as well.{{{ ∇ r←a(f swap)w 0 0⍴⎕FX'r←a' 'r←w' r←w f a |
0 0⍴⎕FX,⊂'r←a r' r←↑a w w |
Line 37: | Line 33: |
r←a dex swap w | r←↑a w w |
Line 39: | Line 35: |
I said `if` did as you'd expect. Here it is.{{{ }}} |
Contents
Some useful operators
dfns.dws
This useful collection of utility functions and operators, dfns.dws, is of use only to users of DyalogAPL as they are all written in the functional subset, d-fns or direct functions, currently implemented only there.
A translation
The present author has decided to translate some of the more useful of the operators into standard, APL2 compatible, APL. This will necessarily exclude control structures, not implemented in APL2, as well as the guard control that characterises d-fns. This leaves only two choices for function flow control. Labels: and branches → or the use of some of the members of the collection whose sole purpose is precisely to provide flow control without branching. The latter is his choice.
So to start, here's an operator, if, that does what you might expect.
∇ r←(f if g)w r←⊃dex join(f join lev)/(⍳1∊g lev w),⊂w ∇
Ok, here's the problem. We've already called three other things, dex, join & lev, we know nothing about so without further ado we'll define them as well.
∇ r←a dex r ∇ ∇ r←a(f join g)w 0 0⍴⎕FX,⊂'r←a r' r←a f g w ∇ ∇ r←a lev w 0 0⍴⎕FX,⊂'r←a r' r←↑a w w ∇
Now you may have noticed something you might think of as unusual in those ⎕FXs. Functions and operators that it makes sense to call ambivalently require a measure of flow control to accommodate both the monadic and dyadic cases. I've chosen to make use of the system's own ambivalence to the attempt to fix a function whose name is already in use as a variable. So if the left argument is supplied it stands as is. If not then a homonymous function is fixed that will stand in its stead. And because this will happen quite a lot here's a function that'll do it for us.
∇ Elided Elided 0 0⍴⎕FX,⊂'r←',Elided,' r' ∇
What it does is replace an elided left argument with an identity function of the same name. You'll see why in a bit. Here are join & lev again looking nicer.
∇ r←a(f join g)w Elided'a' r←a f g w ∇ ∇ r←a lev w Elided'a' r←↑a w w ∇
-- PhilLast 2010-09-09 00:26:04
I said if did as you'd expect. Here it is.