Gimp - 2.4 Guía Del Usuario

Descargar
Página de 653
GNU Image Manipulation Program
146 / 653
(define (AddXY inX inY) (+ inX inY) )
AddXY
is the function’s name and inX and inY are the variables. This function takes its two parameters and adds them together.
If you’ve programmed in other imperative languages (like C/C++, Java, Pascal, etc.), you might notice that a couple of things are
absent in this function definition when compared to other programming languages.
• First, notice that the parameters don’t have any "types" (that is, we didn’t declare them as strings, or integers, etc.). Scheme is
a type-less language. This is handy and allows for quicker script writing.
• Second, notice that we don’t need to worry about how to "return" the result of our function -- the last statement is the value
"returned" when calling this function. Type the function into the console, then try something like:
(AddXY (AddXY 5 6) 4)
11.3.3
Lists, Lists And More Lists
We’ve trained you in variables and functions, and now enter the murky swamps of Scheme’s lists.
11.3.3.1
Defining A List
Before we talk more about lists, it is necessary that you know the difference between atomic values and lists.
You’ve already seen atomic values when we initialized variables in the previous lesson. An atomic value is a single value. So,
for example, we can assign the variable "x" the single value of 8 in the following statement:
(let* ( (x 8) ) x)
(We added the expression x at the end to print out the value assigned to x-- normally you won’t need to do this. Notice how
let* operates just like a function: The value of the last statement is the value returned.)
A variable may also refer to a list of values, rather than a single value. To assign the variable x the list of values 1, 3, 5, we’d
type:
(let* ( (x ’(1 3 5))) x)
Try typing both statements into the Script-Fu Console and notice how it replies. When you type the first statement in, it simply
replies with the result:
8
However, when you type in the other statement, it replies with the following result:
(1 3 5)
When it replies with the value 8 it is informing you that x contains the atomic value 8. However, when it replies with (1 3 5), it
is then informing you that x contains not a single value, but a list of values. Notice that there are no commas in our declaration
or assignment of the list, nor in the printed result.
The syntax to define a list is:
’(a b c)
where a, b, and c are literals. We use the apostrophe (’) to indicate that what follows in the parentheses is a list of literal values,
rather than a function or expression.
An empty list can be defined as such:
’()