The languages and some object-oriented languages
if pressure is above 10 MPa then close valve
Lists are data structures that allow words, numbers, and symbols to be combined in a wide variety of ways. They are useful for symbol manipulation and are a feature of Lisp and Prolog. The above example could be represented as a list in Lisp or Prolog, respectively, as follows:
10.4.2 Other data types
As well as lists, there is a number of other data types available in the AI languages. Unlike most other languages, variables in the AI languages can be used to store any type of data. A list could be assigned to a given variable immediately after assigning a real number to the same variable. The declaration of variables is not always necessary. However, declarations are normally made in Lisp to specify explicitly the scope of a variable, because undeclared variables are assumed to be global (i.e., memory is allocated for the whole duration of a program or interactive session).
|
|
|
|
During the execution of a program, various data structures may be created. There is, therefore, a need for management of the computer memory, i.e., memory must be allocated when needed and subsequently reclaimed. In languages such as C, the responsibility for memory management rests with the programmer, who must allocate and reclaim memory at appropriate places in the program using the malloc and free commands (or their equivalent). In the AI languages (and some object-oriented languages, such as Smalltalk — see Chapter 4) the memory is managed automatically. The programming environment must be capable of both dynamically allocating memory and freeing memory that is no longer required. The latter process is called garbage collection. This is a useful facility, although it can result in a momentary pause in the computer’s response while the garbage collection takes place.
10.4.3 Programming environments