[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: escaping from a recursive call
From: |
Olivier Dion |
Subject: |
Re: escaping from a recursive call |
Date: |
Wed, 09 Nov 2022 11:51:55 -0500 |
On Wed, 09 Nov 2022, Damien Mattei <damien.mattei@gmail.com> wrote:
> i need a way to escape not only the current call of a recursive function
> (it is already done) but alls:
>
> example:
>
> (def (foo n)
> (cond ((= n 0) 'end0)
> ((= n 7) (return 'end7))
> (else (cons n (foo {n - 1})))))
Is that what you want?
--8<---------------cut here---------------start------------->8---
(use-modules
(ice-9 control))
(define (foo n)
(let/ec return
(let loop ((n n))
(cond
((= n 0) 'end0)
((= n 7) (return 'end7))
(else
(cons n (loop (1- n))))))))
(pk (foo 5))
(pk (foo 10))
--8<---------------cut here---------------end--------------->8---
--
Olivier Dion
oldiob.dev
- escaping from a recursive call, Damien Mattei, 2022/11/09
- Re: escaping from a recursive call,
Olivier Dion <=
- Re: escaping from a recursive call, Damien Mattei, 2022/11/09
- Re: escaping from a recursive call, Olivier Dion, 2022/11/09
- Re: escaping from a recursive call, Damien Mattei, 2022/11/09
- Re: escaping from a recursive call, Olivier Dion, 2022/11/09
- Re: escaping from a recursive call, tomas, 2022/11/09
- Re: escaping from a recursive call, Damien Mattei, 2022/11/10
- Re: escaping from a recursive call, Damien Mattei, 2022/11/10
- Re: escaping from a recursive call, Olivier Dion, 2022/11/10
- Re: escaping from a recursive call, Chris Vine, 2022/11/10
- Re: escaping from a recursive call, Damien Mattei, 2022/11/10