apply
apply(slu_func[g_arg ...] l_args) =>g_result
Description
Applies the given function to the given argument list.
apply takes two or more arguments. The first argument must be the name of a function, or a function object, or a list containing a lambda/nlambda/macro expression. The remainder of the arguments are used to construct the list of arguments passed to the function specified by the first argument; the g_arg arguments are individual arguments, which are prepended to the l_args argument to create a combined list of arguments.
The argument list l_args is bound to the formal arguments of slu_func according to the type of function. For lambda functions the length of l_args should match the number of formal arguments, unless keywords or optional arguments exist. For nlambda and macro functions, l_args is bound directly to the single formal parameter of the function.
apply evaluates it only once, that is, it expands it and returns the expanded form, but does not evaluate the expanded form again (as eval does).Arguments
|
Optional arguments that are prepended to l_args to create a combined list of arguments. |
|
Value Returned
Examples
apply('plus (list 1 2) ) ; Apply plus to its arguments.
=> 3
procedure( sumTail(l) apply( 'plus cdr(l)))
=> sumTail ;Define a procedure
sumTail( '(1 2 3))
=> 5
apply('plus list(1 2 3 4)) ; adds 1, 2, 3 and 4
=> 10
apply('plus 1 2 list(3 4)) ; adds 1, 2, 3 and 4.
=> 10
Related Topics
Function and Program Structure
Return to top