User Guide
GNU Image Manipulation Program
145 / 653
11.3.2.2 What Is A Local Variable?
You’ll notice that we wrote the summation (+ a b) within the parens of the let
*
expression, not after it.
This is because the let
*
statement defines an area in your script in which the declared variables are usable; if you type the (+ a
b) statement after the (let* ...) statement, you’ll get an error, because the declared variables are only valid within the context of
the let
*
statement; they are what programmers call local variables.
11.3.2.3 The General Syntax Of let
*
The general form of a let
*
statement is:
(let
*
( variables )
expressions )
where variables are declared within parens, e.g., (a 2), and expressions are any valid Scheme expressions. Remember that the
variables declared here are only valid within the let
*
statement -- they’re local variables.
11.3.2.4 White Space
Previously, we mentioned the fact that you’ll probably want to use indentation to help clarify and organize your scripts. This
is a good policy to adopt, and is not a problem in Scheme -- white space is ignored by the Scheme interpreter, and can thus be
liberally applied to help clarify and organize the code within a script. However, if you’re working in Script-Fu’s Console window,
you’ll have to enter an entire expression on one line; that is, everything between the opening and closing parens of an expression
must come on one line in the Script-Fu Console window.
11.3.2.5 Assigning A New Value To A Variable
Once you’ve initialized a variable, you might need to change its value later on in the script. Use the set! statement to change the
variable’s value:
(let
*
( (theNum 10) ) (set! theNum (+ theNum \
theNum)) )
Try to guess what the above statement will do, then go ahead and enter it in the Script-Fu Console window.
Note
The ‘\’ indicates that there is no line break. Ignore it (don’t type it in your Script-Fu console and don’t hit Enter), just
continue with the next line.
11.3.2.6 Functions
Now that you’ve got the hang of variables, let’s get to work with some functions. You declare a function with the following
syntax:
(define
(
name
param-list
)
expressions
)
where name is the name assigned to this function, param-list is a space-delimited list of parameter names, and expressions
is a series of expressions that the function executes when it’s called. For example: