case-lambda -- r7rs Definition syntax;
case-lambda (from vonuvoli);Syntax keywords:
argument: identifier;argument-rest: identifier;arguments: pattern with variants:
();(argument |...|);(argument |...| . argument-rest);argument-rest;expression: expression;Syntax variants:
(_ (arguments expression) |...|)scheme:case-lambda -- (scheme case-lambda);scheme -- (scheme);(case-lambda <clause> ...)Syntax: Each
<clause>is of the form(<formals> <body>), where<formals>and<body>have the same syntax as in alambdaexpression.Semantics: A
case-lambdaexpression evaluates to a procedure that accepts a variable number of arguments and is lexically scoped in the same manner as a procedure resulting from alambdaexpression. When the procedure is called, the first<clause>for which the arguments agree with<formals>is selected, where agreement is specified as for the<formals>of alambdaexpression. The variables of<formals>are bound to fresh locations, the values of the arguments are stored in those locations, the<body>is evaluated in the extended environment, and the results of<body>are returned as the results of the procedure call.It is an error for the arguments not to agree with the
<formals>of any<clause>.(define range (case-lambda ((e) (range 0 e)) ((b e) (do ((r '() (cons e r)) (e (- e 1) (- e 1))) ((< e b) r))))) (range 3) ===> (0 1 2) (range 3 5) ===> (3 4)
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.