Differences between revisions 6 and 7
Revision 6 as of 2009-10-26 07:41:47
Size: 416
Editor: anonymous
Comment:
Revision 7 as of 2010-09-09 00:26:04
Size: 2460
Editor: anonymous
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 ==
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.
Line 8: Line 6:
Email: <<MailTo(phil.last AT ntlworld DOT com)>> 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.
Line 10: Line 8:
Independent APL programmer.
 At some time or other !PhilLast has put his name to changes in the following pages:
<<FullSearch("-- PhilLast <<Da")>>
----
CategoryHomepage
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 don't know about so without further ado we'll define them as well.{{{
∇ r←a dex w
  r←w

∇ r←a(f join g)w
  0 0⍴⎕FX 1 5⍴'r←a r'
  r←a f g w

∇ r←a lev w
  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
∇}}}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 dex swap w
∇}}}-- PhilLast <<DateTime(2010-09-09T01:26:04+0100)>>

Some useful operators

A 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.

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.

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 don't know about so without further ado we'll define them as well.

∇ r←a dex w
  r←w
∇ r←a(f join g)w
  0 0⍴⎕FX 1 5⍴'r←a r'
  r←a f g w
∇ r←a lev w
  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

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 dex swap w

-- PhilLast 2010-09-09 00:26:04

TestPhil (last edited 2010-09-09 23:53:13 by anonymous)