[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Repeat syntax
From: |
Matt Wette |
Subject: |
Re: Repeat syntax |
Date: |
Sat, 25 Nov 2017 06:47:38 -0800 |
> On Nov 24, 2017, at 9:05 PM, Christopher Howard <address@hidden> wrote:
>
> Hi list, I want to have a function
>
> (repeat n exp exp* ...)
>
> That calls the expressions n times for side effect, like for-each, but
> without the bother of dealing with a list. It seems like somebody else
> must have thought of this before, but I couldn't find the equivalent
> procedure. After reading 6.10.2 I came up with this
>
> (define-syntax repeat
> (syntax-rules (repeat)
> ((_ n exp exp* ...)
> '(unless (<= n 0)
> exp
> exp*
> ...
> (repeat (- n 1) exp exp* ...)))))
>
> Which doesn't work I think because repeat gets expanded infinitely many
> times. I was pondering other ways to do this, but they all seem to end
> in either infinite expansion, or an important variable getting
> overshadowed. So, could somebody point me in the right direction?
>
> --
> https://emailselfdefense.fsf.org/en/
you probably want named let
((_ n exp exp* ...)
(let loop ((n n))
(unless (<= n 0)
exp exp* ...
(loop (1- n)))