defun


(defun  name  ( [ args ... [ / vars ... ] ) expr ... )

This function defines a user-defined Lisp function command.

Arguments

name  name of Lisp function (if prefixed by C: then the Lisp function is also a command)

args  (optional) 1 or more Lisp symbols, passed to this function as arguments

vars  (optional) 1 or more Lisp symbols, declared as local variables, which are only valid within this function

expr  1 or more Lisp expressions to be evaluated

Return

name  if the function was successfully registered; otherwise a Lisp error is triggered;
returns the result of last evaluated expr, when name function is called via (name)

Example

(defun lenghOf ( lst / res ) (setq res (length lst)))  returns the length of a list
(defun C:Test () (alert "Hello"))  defines a TEST command

Remarks

if 'name' is prefixed by C: then a command is registered, which can be directly called at commandline, by entering name;
a C: Lisp command must not use the args arguments;
calling (c:name) is also valid to run the function via Lisp;
all local variables are automatically preset as NIL;

if args or vars are used, the / delimiter *MUST* be surrounded by at least 1 space to the left + right !



©  Bricsys NV. All rights reserved.