Tag Archives: Declarative programming

Lisp Computer Programming

The code below shows common functions executed through lisp, a declarative programming language. One reason that Lisp is used for Artificial Intelligence is that it is an excellent prototyping tool. Also, Lisp supports symbolic programming well. Old AI was also symbolic. In addition, the code/data distinction in lisp is weaker so it feels more extensible than other languages because your functions and macros look like the built-in stuff (Stack Overflow).

(write-line “Hello World”)
(defun add (X Y)
“Compute three times X.”
(+ Y X))

(print (add 3 3)) ; Display that function with 4 as a param

(defun subtract (X Y)
“Compute three times X.”
(- X Y))

(print (subtract 4 3)) ; Display that function with 4 as a param

(defun multiplication (X Y)
“Compute three times X.”
(* X Y))

(print (multiplication 3 3)) ; Display that function with 4 as a param

(defun factorial (n)
(if (<= n 1)
1 ; returns 1 once you go through all the numbers
;hidden else statement here
(* n (factorial (- n 1)))))

(print (factorial 5))

Tagged ,