#acl PhilLast:read,write All: <> = 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. 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 <> I said `if` did as you'd expect. Here it is.{{{ }}}