r7rs-small-texinfo

R7RS-small Scheme converted to Texinfo.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

sequencing.texinfo (1441B)


      1 @node Sequencing
      2 @subsection Sequencing
      3 
      4 Both of Scheme's sequencing constructs are named @code{begin}, but the two have slightly
      5 different forms and uses:
      6 
      7 @deffn syntax begin @svar{expression or definition}@dots{}
      8 
      9 This form of begin can appear as part of a @svar{body}, or at the outermost level of a
     10 @svar{program}, or at the REPL, or directly nested in a @code{begin} that is itself of this form. It causes
     11 the contained expressions and definitions to be evaluated exactly as if the enclosing @code{begin}
     12 construct were not present.
     13 
     14 Rationale: This form is commonly used in the output of macros (@xref{Macros}) which
     15 need to generate multiple definitions and splice them into the context in which they
     16 are expanded.
     17 
     18 @end deffn
     19 
     20 @deffn syntax begin @svar{expression@sub{1}} @svar{expression@sub{2}}@dots{}
     21 
     22 This form of @code{begin} can be used as an ordinary expression. The @svar{expression}s are
     23 evaluated sequentially from left to right, and the values of the last @svar{expression} are
     24 returned. This expression type is used to sequence side effects such as assignments or
     25 input and output.
     26 
     27 @lisp
     28 (define x 0)
     29 
     30 (and (= x 0)
     31      (begin (set! x 5)
     32             (+ x 1))) @result{} 6
     33 
     34 (begin (display "4 plus 1 equals ")
     35        (display (+ 4 1)))
     36        @result{} @r{unspecified}
     37 @print{} 4 plus 1 equals 5
     38 @end lisp
     39 
     40 @end deffn
     41 
     42 Note that there is a third form of @code{begin} used as a library declaration.
     43 @xref{Library syntax}