[plt-scheme] contract & tail recursion

From: YC (yinso.chen at gmail.com)
Date: Fri Sep 12 14:55:18 EDT 2008

On Fri, Sep 12, 2008 at 12:18 AM, John Clements
<clements at brinckerhoff.org>wrote:

>
> When you say that "any" is tail recursive, I believe what you actually mean
> is that a procedure that uses "any" as its result contract can still be
> tail-calling (or tail recursive, if you prefer).  This is because the "any"
> contract is satisfied by any value, so no check need be performed.
>
> In other cases, though, you can't have tail-calling; this is because the
> contract that you're specifying requires a check after the return of the
> procedure that the contract is applied to.
>
> To be more concrete:  suppose you have a function f that's wrapped with a
> number? -> number? contract.  Calls to f can never be tail calls, because
> the current continuation must be extended with a check that the result value
> is a number.
>

Thanks for the response. I apologize for my unclear writing.

What you say makes sense, to me it means that if we care about space
efficiency we cannot use anything besides `any` for the result contract,
unless we can foresee how the function would be used ahead of time, or have
a way to conditionally circumvent contracts.

Thanks,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080912/dbbb94f4/attachment.html>

Posted on the users mailing list.