[comp.lang.apl] Double and Hook

ljdickey@watmath.waterloo.edu (L.J.Dickey) (06/11/91)

In article <ROCKWELL.91Jun6222025@socrates.umd.edu>
	rockwell@socrates.umd.edu (Raul Rockwell) writes:
>I used f :'' and f@] in my last post ...

Along the same vein, comparing features in J:

The adverb "~" (double) has the effect of causing a monadic
function call to be treated dyadically by doubling the right
argument:

	f~ x   <-->   x f x

This is nice for building tables, for instance, as in
	+/ ~ i. 4
because you don't have to type the "i. 4" twice, and sometimes
it cuts down on the need for parentheses  (compare
	(i. 4) +/ i. 4
for example).

Now, to get to my point.
Double can be simulated by the hook.  Consider any function f,
and compare

	f ~ x        
	f ] x

To take a specific example, consider these three function.
   pr =. +%
   f1 =. pr ~
   f2 =. pr ]
Then
   f1 4 5
4.25 5.2
   f2 4 5
4.25 5.2

Showing that the hook (used in f2) produces the same result as
the double (used in f1).  Of course the functions f1 and f1 are
not identical, since dyadic usages are different, as in
   4 f1 5
5.25
   4 f2 5
4.2

--
Prof L.J. Dickey, Faculty of Mathematics, U of Waterloo, Canada N2L 3G1
internet:       ljdickey@watmath.UWaterloo.ca	BITNET/EARN:	ljdickey@watdcs
obsolescent?:	ljdickey@watmath.waterloo.edu
UUCP:		ljdickey@watmath.UUCP	..!uunet!watmath!ljdickey