guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q on tail-call


From: Taylan Ulrich Bayırlı/Kammer
Subject: Re: Q on tail-call
Date: Sun, 15 Feb 2015 23:36:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Matt Wette <address@hidden> writes:

> Is the following (incomplete) construct tail recursive?  The name-call
> is wrapped inside a "trivial" closure.
>
>  (let ITER ((res '()) (st 1) (nd 1))
>       (cond
>        ((string-contains str "," st) => (lambda (pos) (ITER res st pos)))))
>
> I tried to use "(compile 'above :from 'scheme :to 'xlil)" (and
> others), but the code was not readable for me.
>
> Matt

As per section "3.5. Proper tail recursion" of R5RS, page 8:

- If a cond expression is in tail context, and has a clause of the form
  (<expression1> => <expression2>) then the (implied) call to the
  procedure that results from the evaluation of <expression2> is in a
  tail context.

and the call to ITER within that procedure is, in turn, in tail context,
so yes, execution will jump from cond's code to your lambda's code,
which will in turn jump to ITER's code, all without stacking up frames.

Taylan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]