Size: 416
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 1: | Line 1: |
## page was copied from PhilLast ##master-page:HomepageTemplate #format wiki |
|
Line 5: | Line 2: |
||<tablestyle="float:right">{{attachment:philspic.jpg}}|| == Phil Last == |
<<TableOfContents>> = 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 8: | Line 9: |
Email: <<MailTo(phil.last AT ntlworld DOT com)>> | 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 `⎕FX`s. 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 <<DateTime(2010-09-09T01:26:04+0100)>> |
Line 10: | Line 36: |
Independent APL programmer. At some time or other !PhilLast has put his name to changes in the following pages: <<FullSearch("-- PhilLast <<Da")>> ---- CategoryHomepage |
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.