XLISP apply

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# 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

The 'apply' function causes 'function' to be evaluated with 'args' as the parameters, returning the result of 'function'. The 'args' argument must be a list.

## Examples

    > (defun my-add (x y)        ; define MY-ADD function
        (+ x y))
    MY-ADD

    > (my-add 1 2)               ; ordinary function call
    3                            ; returns 3

    > (apply #'my-add '(2 4))    ; symbol-function applied to argument-list
    6                            ; returns 6

Note: When using 'apply' to cause the evaluation of a function, you can use the sharp-quoted name of the function like #'my-add in the example, or (function my-add). In XLISP also 'my-add and (quote my-add) work, but this is no good Lisp style.

See also:

- Contents → Evaluation Functions

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference