Gimp - 2.4 Guía Del Usuario

Descargar
Página de 653
GNU Image Manipulation Program
144 / 653
Knowing that the + operator can take a list of numbers to add, you might be tempted to convert the above to the following:
(+ 3 (5 6) 7)
However, this is incorrect -- remember, every statement in Scheme starts and ends with parens, so the Scheme interpreter will
think that you’re trying to call a function named ‘5’ in the second group of parens, rather than summing those numbers before
adding them to 3.
The correct way to write the above statement would be:
(+ 3 (+ 5 6) 7)
11.3.1.6
Make Sure You Have The Proper Spacing, Too
If you are familiar with other programming languages, like C/C++, Perl or Java, you know that you don’t need white space
around mathematical operators to properly form an expression:
3+5, 3 +5, 3+ 5
These are all accepted by C/C++, Perl and Java compilers. However, the same is not true for Scheme. You must have a space
after a mathematical operator (or any other function name or operator) in Scheme for it to be correctly interpreted by the Scheme
interpreter.
Practice a bit with simple mathematical equations in the Script-Fu Console until you’re totally comfortable with these initial
concepts.
11.3.2
Variables And Functions
Now that we know that every Scheme statement is enclosed in parentheses, and that the function name/operator is listed first, we
need to know how to create and use variables, and how to create and use functions. We’ll start with the variables.
11.3.2.1
Declaring Variables
Although there are a couple of different methods for declaring variables, the preferred method is to use the let* construct. If
you’re familiar with other programming languages, this construct is equivalent to defining a list of local variables and a scope in
which they’re active. As an example, to declare two variables, a and b, initialized to 1 and 2, respectively, you’d write:
(let*
(
(a 1)
(b 2)
)
(+ a b)
)
or, as one line:
(let* ( (a 1) (b 2) ) (+ a b) )
Note
You’ll have to put all of this on one line if you’re using the console window. In general, however, you’ll want to adopt a
similar practice of indentation to help make your scripts more readable. We’ll talk a bit more about this in the section on
White Space.
This declares two local variables, a and b, initializes them, then prints the sum of the two variables.