Use additional arguments when a function needs to know what other arguments to the function have been like so far.
Use (letrec ...)
to remove arguments that do not change for recursive application.
However, in some Scheme dialects one can also use define
in all or most contexts (definition contexts), so that one does not need to use letrec
.
Use src_scheme[:exports code]{(letrec ...)} to hide and to protect functions.
Use src_scheme[:exports code]{(letcc ...)} to return values abruptly and promptly.
However, in Scheme dialects, it is called src_scheme[:exports code]{(call-with-current-continuation ...)} instead. One could write a macro transforming it into src_scheme[:exports code]{(letrec ...)} though.
Use src_scheme[:exports code]{(let ...)} to name the values of repeated expressions in a function definition if they may be evaluated twice for one and the same use of the function.
Use src_scheme[:exports code]{(set! ...)} only with names defined in src_scheme[:exports code]{(let ...)}s.
(Or equivalent constructs, such as src_scheme[:exports code]{(define ...)} inside a procedure definition.)
Use src_scheme[:exports code]{(set! x ...)} for src_scheme[:exports code]{(let ([x ...]) ...)} only, if there is at least one src_scheme[:exports code]{(lambda ...} between it and the src_scheme[:exports code]{(let ([x ...]) ...)}.
Use src_scheme[:exports code]{(set! x ...)} only when the value that src_scheme[:exports code]{x} refers to is no longer needed.