Return values
Scheme procedures always return a return value, which is the value
of the last expression executed in the procedure. The return
value can be any valid Scheme value, including a complex data
structure or a procedure.
Sometimes the user would like to have multiple Scheme expressions in
a procedure. There are two ways that multiple expressions can be
combined. The first is the begin procedure, which allows
multiple expressions to be evaluated, and returns the value of
the last expression.
| | guile> (begin (+ 1 2) (- 5 8) (* 2 2))
4
|
The second way to combine multiple expressions is in a let block.
In a let block, a series of bindings are created, and then a sequence
of expressions that can include those bindings is evaluated. The
return value of the let block is the return value of the last
statement in the let block:
| | guile> (let ((x 2) (y 3) (z 4)) (display (+ x y)) (display (- z 4))
… (+ (* x y) (/ z x)))
508
|