unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Q on tail-call
@ 2015-02-15 15:07 Matt Wette
  2015-02-15 22:36 ` Taylan Ulrich Bayırlı/Kammer
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Wette @ 2015-02-15 15:07 UTC (permalink / raw)
  To: guile-user

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Q on tail-call
  2015-02-15 15:07 Q on tail-call Matt Wette
@ 2015-02-15 22:36 ` Taylan Ulrich Bayırlı/Kammer
  0 siblings, 0 replies; 2+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2015-02-15 22:36 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

Matt Wette <mwette@alumni.caltech.edu> 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-15 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-15 15:07 Q on tail-call Matt Wette
2015-02-15 22:36 ` Taylan Ulrich Bayırlı/Kammer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).