Книга: Introduction to Microprocessors and Microcontrollers

Lisp

Lisp

Lisp was designed about the same time as Cobol and several years before Basic. It is the work of an American, John McCarthy (see Figure 10.11).


Figure 10.11 Lisp – dealing with lists

Lisp (LISt Processing) involves the manipulation of data which is held in lists or entered by keyboard and is associated with artificial intelligence. Lisp is a function-oriented language. This means that we define a function, such as add, subtract or more complex combinations. A list consists of a series of ‘members’ separated by spaces and enclosed in brackets. Samples of lists are (2 5 56 234) or (mother father son daughter).

A simple function defined as (PLUS 6 4) would return the answer 10 by adding the two numbers. Since it is an interpreted language, the program is executed one step at a time so inputted values are used as they are entered. In some versions of Lisp, this would have been written as (+ 6 4) using the mathematical symbol.

We can define our own function by saying

(defun result (A B)(+A B))

defun = define function and A B are inputted numbers and the answers have been given the name ‘result’. So, if we input the numbers 4 and 5 we would receive the response 9. This has defined a function in which we enter two numbers A and B and they are added. We could use this to enter a list of values for A and B generating a list of all the results.

Оглавление книги


Генерация: 0.426. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз