Search Top Index
HELP APPLY Steven Hardy, January 1978 apply(<procedure>) or apply(<argument>, <procedure>) This procedure takes as argument a procedure, which it applies. If the procedure needs arguments these should also be given to APPLY (unless they are already on the stack when APPLY is called). For example: apply([a b c], hd) => ** a A common use of APPLY is when one wishes to apply a procedure which is the result of some expression; for example, suppose that the procedure PRFUN when applied to an object produces a procedure which can be applied to the object to print it. (It is a good idea to have a separate printing procedure for each kind of object, because the requirements for, say, lists will be so different from the requirements for numbers.) The general procedure PR could be defined as: define pr(object); apply(object, prfun(object)); enddefine; However, it will often be clearer to write: define pr(object); prfun(object)(object) enddefine; APPLY could be defined as: define apply(f); f(); enddefine; define updaterof apply(f); -> f() enddefine; See also HELP *UPDATEROF - to define the updater of a procedure *APPDATA - to apply a procedure to each element of a data structure *MAPDATA - like MAPDATA but returns a copy of the altered structure *CHAIN - exits from a procedure and calls another *PDCOMP - constructs a procedure out of other procedures *ISPROCEDURE - recogniser for procedures