Gimp - 2.4 Guía Del Usuario

Descargar
Página de 653
GNU Image Manipulation Program
148 / 653
11.3.3.5
Accessing Values In A List
To access the values in a list, use the functions car and cdr, which return the first element of the list and the rest of the list,
respectively. These functions break the list down into the head::tail construct I mentioned earlier.
11.3.3.6
The
car
Function
car
returns the first element of the list (the head of the list). The list needs to be non-null. Thus, the following returns the first
element of the list:
(car ’("first" 2 "third"))
which is:
"first"
11.3.3.7
The
cdr
function
cdr
returns the rest of the list after the first element (the tail of the list). If there is only one element in the list, it returns an
empty list.
(cdr ’("first" 2 "third"))
returns:
(2 "third")
whereas the following:
(cdr ’("one and only"))
returns:
()
11.3.3.8
Accessing Other Elements In A List
OK, great, we can get the first element in a list, as well as the rest of the list, but how do we access the second, third or other
elements of a list? There exist several "convenience" functions to access, for example, the head of the head of the tail of a list
(caadr), the tail of the tail of a list (cddr), etc.
The basic naming convention is easy: The a’s and d’s represent the heads and tails of lists, so
(car (cdr (car x) ) )
could be written as:
se podría escribir como:
(cadar x)
To view a full list of the list functions, refer to the Appendix, which lists the available functions for the version of Scheme used
by Script-Fu.
To get some practice with list-accessing functions, try typing in the following (except all on one line if you’re using the console);
use different variations of car and cdr to access the different elements of the list: