r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

case-lambda.texinfo (1283B)


      1 @node Case-lambda
      2 @subsection Case-lambda
      3 
      4 @deffn {library syntax} case-lambda @svar{clause}@dots{}
      5 
      6 Syntax: Each @svar{clause} is of the form
      7 @code{(}@svar{formals} @svar{body}@code{)}, where @svar{formals} and @svar{body}
      8 have the same syntax as in a @code{lambda} expression.
      9 
     10 Semantics: A @code{case-lambda} expression evaluates to a procedure that accepts a variable
     11 number of arguments and is lexically scoped in the same manner as a procedure resulting
     12 from a @code{lambda} expression. When the procedure is called, the first @svar{clause} for which the
     13 arguments agree with @svar{formals} is selected, where agreement is specified as for the
     14 @svar{formals} of a lambda expression. The variables of @svar{formals} are bound to fresh
     15 locations, the values of the arguments are stored in those locations, the @svar{body} is
     16 evaluated in the extended environment, and the results of @svar{body} are returned as the
     17 results of the procedure call.
     18 
     19 It is an error for the arguments not to agree with the @svar{formals} of any @svar{clause}.
     20 
     21 @lisp
     22 (define range
     23   (case-lambda
     24    ((e) (range 0 e))
     25    ((b e) (do ((r '() (cons e r))
     26                (e (- e 1) (- e 1)))
     27               ((< e b) r)))))
     28 
     29 (range 3)    @result{} (0 1 2)
     30 (range 3 5)  @result{} (3 4)
     31 @end lisp
     32 
     33 @end deffn