.he 'PARTAPPLY''Page %'
.fo 'Steven Hardy''January 78'
PARTAPPLY	This function produces 'closures' of existing functions.  It
takes two arguments - a  function and a list;  its result is
a new function based upon the given function, but requiring fewer
arguments, the rightmost of the arguments of the given
function being supplied by the values in the list at the time PARTAPPLY
is called.  For example:-
 	: FUNCTION F(X,Y,Z);
 	:	[%X,Y,Z%]
 	: END;
 	: F(1,2,3) =>
 	** [1 2 3]
 	: F(4,5,6) =>
 	** [4 5 6]
 	: VARS G; PARTAPPLY(F,[3]) -> G;
 	: G(1,2) =>
 	** [1 2 3]
 	: G(4,5) =>
 	** [4 5 3]
 	: PARTAPPLY(F,[10 20]) -> G;
 	: G(4) =>
 	** [4 10 20]
.br
Some 'syntactic sugar' is provided so that PARTAPPLY(F,[3]) can be
written as F(%3%).
Partial application is a useful technique  in a
variety of situations.  The most common is to make a general function
more specific.
For example:
 	: VARS ISCOLOUR;
 	: MEMBER(%[RED BLUE GREEN YELLOW]%) -> ISCOLOUR;
 	: ISCOLOUR("RED") =>
 	** 1
 	: ISCOLOUR("APPLE") =>
 	** 0
 	: FUNCTION FINDONE(LIST,PREDICATE);
 	:	IF	LIST = []
 	:	THEN	FALSE
 	:	ELSEIF	PREDICATE(HD(LIST))
 	:	THEN	HD(LIST)
 	:	ELSE	FINDONE(TL(LIST),PREDICATE)
 	:	CLOSE
 	: END;
 	: FINDONE([APPLE RED HOUSE], ISCOLOUR) =>
 	** RED
 	: VARS GETCOLOUR; FINDONE(%ISCOLOUR%) -> GETCOLOUR;
 	: GETCOLOUR([APPLE RED HOUSE]) =>
 	** RED
.br
See also FROZAL, FNPART, above and (% %), in standard syntax words in POP11.
