XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

apply


Type:   -   function (subr)
Source:   -   xlbfun.c

Syntax

(apply function args)
function - the function or symbol to be applied to 'args'
args - a list that contains the arguments to be passed to 'function'
returns - the result of applying the function to the arguments

Description

'apply' causes 'function' to be evaluated with 'args' as the parameters. 'apply' returns the result of 'function'. 'args' must be in the form of a list.

Examples

(defun my-add (x y)              ; create MY-ADD function
  (print "my add")
  (+ x y))
(my-add 1 2)                     ; prints "my add" returns 3
(apply 'my-add '(2 4))           ; prints "my add" returns 6
(apply 'my-add 1 2)              ; error: bad argument type 
(apply 'my-add '(1 2 3))         ; error: too many arguments
(apply (function +) '(9 10))     ; returns 19
(apply '+ '(4 6))                ; returns 10
(apply 'print '("hello there"))  ; prints/returns "hello there"
(apply 'print "hello there")     ; error: bad argument type

Note: When using 'apply' to cause the evaluation of a system function, you can use the quoted name of the function [like 'print in the examples]. You can also use the actual function [like (function +) in the examples].

See the apply function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next