Re: [Scheme-reports] practical matters - CSAN
John Cowan 29 Aug 2011 16:59 UTC
Aubrey Jaffer scripsit:
> LET-VALUES, LET*-VALUES, and (srfi-8) RECEIVE expect the number of
> bindings to match the number of return values. They can't be used if
> the number of return values is not known in advance.
In fact they can:
(let-value (let (((x y . z) (some-mv-form))) <body>)
will bind the first two values of (some-mv-form) to x and y, and any
remaining values as a list to z.
> CASE-LAMBDA can be used if the desired behavior changes radically with
> different numbers of values; but often there is a lot of commonality
> in the procedure. A shared internal definition can't be called
> because CASE-LAMBDA is the outer binding of the definition. So either
> code must be replicated in each clause or each clause must call an
> external procedure with all the arguments.
A case-lambda can tail-call itself:
(define x (case-lambda
((a b) ...)
((a) (x a 0))))
A compiler can detect this case and optimize it. In addition, the
case-lambda can be wrapped in a letrec containing internal definitions
visible to the case-lambda.
--
BALIN FUNDINUL UZBAD KHAZADDUMU cowan@ccil.org
BALIN SON OF FUNDIN LORD OF KHAZAD-DUM http://www.ccil.org/~cowan
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports