(let* ( (a 1) (b 2) ) (+ a b) )
or, as one line:
(let* ( (a 1) (b 2) ) (+ a b) )
![]() |
Not |
---|---|
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.
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.
(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.
(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.
![]() |
Not |
---|---|
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. |
(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:
(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)