Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

apply

apply

type: function (subr) 
location: built-in
source file: xlbfun.c
Common LISP compatible: yes
supported on: all machines

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>

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: Note that 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).


Go to the first, previous, next, last section, table of contents.