defun

defun

defun (short for "define function") is a macro in the Lisp family of programming languages that defines a function in the global environment[1] that uses the form:[2]

(defun <function-name> (<parameter1><parameter2>...<parameterN>) 
  functionbody)

Defining the function addnumbers that adds two numbers:

 ;; Define a function that adds two numbers together:
 (defun addnumbers (number1 number2)
   (+ number1 number2))
 (addnumbers 5 4)
 9

defining function square that squares a number:

 ;; Define a function that squares a number:
 (defun square (x) 
   (* x x))

and defining a function that returns the factorial of a number:

(defun factorial (number)
  (if (= number 1)
      1
    (* number (factorial (- number 1)))))
(factorial 6)
720

See also

References

  1. ^ Macro DEFUN
  2. ^ [1]

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • DEFUN — defunctae …   Abbreviations in Latin Inscriptions

  • Common Lisp — Paradigm(s) Multi paradigm: procedural, functional, object oriented, meta, reflective, generic Appeared in 1984, 1994 for ANSI Common Lisp Developer ANSI X3J13 committee Typing discipline …   Wikipedia

  • Common-Lisp — Inoffizielles Lisp Logo Basisdaten Paradigmen: multiparadigmatisch: funktional, prozedural …   Deutsch Wikipedia

  • Common LISP — Inoffizielles Lisp Logo Basisdaten Paradigmen: multiparadigmatisch: funktional, prozedural …   Deutsch Wikipedia

  • Common Lisp — Inoffizielles Lisp Logo Basisdaten Paradigmen: multiparadigmatisch: funktional, prozedural, modular, objektorientiert …   Deutsch Wikipedia

  • Common Lisp — est un langage fonctionnel impur de la famille Lisp. Sommaire 1 Introduction 2 Syntaxe 3 Types de données 3.1 Types scalaires …   Wikipédia en Français

  • Lisp (programming language) — Infobox programming language name = Lisp paradigm = multi paradigm: functional, procedural, reflective generation = 3GL year = 1958 designer = John McCarthy developer = Steve Russell, Timothy P. Hart, and Mike Levin latest release version =… …   Wikipedia

  • AutoLISP — [ˈɑːtoʊˌlɪsp] ist ein Dialekt der Programmiersprache LISP als Bestandteil des verbreiteten CAD Programmes AutoCAD. Mit Hilfe von AutoLisp können Funktionen in einem AutoCAD System hinzugefügt, gelöscht und geändert werden. Um dies zu… …   Deutsch Wikipedia

  • AutoLisp — [ˈɑːtoʊˌlɪsp] ist ein Dialekt der Programmiersprache LISP als Bestandteil des verbreiteten CAD Programmes AutoCAD. Mit Hilfe von AutoLisp können Funktionen in einem AutoCAD System hinzugefügt, gelöscht und geändert werden. Um dies zu… …   Deutsch Wikipedia

  • Gestion d'exceptions — Système de gestion d exceptions Dans le contexte des langages de programmation fonctionnels et impératifs, un système de gestion d exceptions ou SGE permet de gérer les conditions exceptionnelles pendant l exécution du programme. Lorsqu une… …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”