From 13c348d4193febce39c4bce166f9a8f2ff6639fc Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 10 Dec 2016 03:59:51 -0500 Subject: [PATCH] WIP --- docs/api/scheme/case-lambda.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/api/scheme/case-lambda.md b/docs/api/scheme/case-lambda.md index 0e9035ac..6471b234 100644 --- a/docs/api/scheme/case-lambda.md +++ b/docs/api/scheme/case-lambda.md @@ -8,8 +8,24 @@ For more information see the [R7RS Scheme Specification](../../r7rs.p # case-lambda +*Syntax* + (case-lambda {clause} ...) Syntax: Each `{clause}` is of the form `({formals} {body})`, where `{formals}` and `{body}` have the same syntax as in a lambda expression. Semantics: A `case-lambda` expression evaluates to a procedure that accepts a variable number of arguments and is lexically scoped in the same manner as a procedure resulting from a lambda expression. + +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 a lambda expression. 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)