commandments.org 3.1 KB

11 - The Eleventh Commandment - Accumulation of results or maintaining state

Use additional arguments when a function needs to know what other arguments to the function have been like so far.

12 - The Twelfth Commandment - Avoiding of unchanging iteration arguments

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.

13 - The Thirteenth Commandment - Usage of src_scheme[:exports code]{(letrec ...)} or named src_scheme[:exports code]{let} or inner src_scheme[:exports code]{(define ...)}

Use src_scheme[:exports code]{(letrec ...)} to hide and to protect functions.

14 - The Fourteenth Commandment - Usage of src_scheme[:exports code]{(call-with-current-continuation ...)}

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.

15 - The Fifteenth Commandment - Usage of src_scheme[:exports code]{(let ...)}

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.

16 – The Sixteenth Commandment – Usage of src_scheme[:exports code]{set!}

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.)

17 – The Seventeenth Commandment – src_scheme[:exports code]{let} around src_scheme[:exports code]{lambda} for src_scheme[:exports code]{set!} usage

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 ...]) ...)}.

18 - The Eighteenth Commandment - Usage ods src_scheme[:exports code]{set!} for obsolete bindings only

Use src_scheme[:exports code]{(set! x ...)} only when the value that src_scheme[:exports code]{x} refers to is no longer needed.