begin -- r7rs Definition syntax;
Syntax keywords:
expression: expression;Syntax variants:
(_)(_ expression |...|)scheme:base -- (scheme base);scheme -- (scheme);(begin <expression-or-definition> ...)This form of
begincan appear as part of a<body>, or at the outermost level of a<program>, or at the REPL, or directly nested in abeginthat is itself of this form. It causes the contained expressions and definitions to be evaluated exactly as if the enclosingbeginconstruct were not present.Rationale: This form is commonly used in the output of macros (see section on macros) which need to generate multiple definitions and splice them into the context in which they are expanded.
(begin <expression_1> <expression_2> ...)This form of
begincan be used as an ordinary expression. The<expression>s are evaluated sequentially from left to right, and the values of the last<expression>are returned. This expression type is used to sequence side effects such as assignments or input and output.(define x 0) (and (= x 0) (begin (set! x 5) (+ x 1))) ===> 6 (begin (display "4 plus 1 equals ") (display (+ 4 1))) ===> #unspecified ; and prints: 4 plus 1 equals 5Note that there is a third form of
beginused as a library declaration: see section on libraries.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.