XLISP incf

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

# incf

Type: | - | Lisp macro (closure)
Source: | - | misc.lsp

## Syntax

(incf symbol)
  symbol - a symbol with numerical value bound to it
  returns - the new value of the symbol

In Nyquist, 'incf' is implemented as a Lisp macro:

    (defmacro incf (symbol)
      `(setf ,symbol (1+ ,symbol)))

## Description

The 'incf' macro is used for incrementing a numerical value of a variable. 1 is added to the number and the result is stored in the variable. An error is signalled if the variable doesn't hold a number.

## Examples

    (setq n 1)     => 1
    (incf n)       => 2
    n              => 2
    (incf n)       => 3

    (setq n -1.8)  => -1.8
    (incf n)       => -0.8
    (incf n)       => 0.2
    (incf n)       => 1.2
    n              => 1.2

    (setq n #\a)  => #\a
    (incf a)      => error: bad argument type - #\a

Back to Top

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