[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Repeat syntax
From: |
Christopher Howard |
Subject: |
Re: Repeat syntax |
Date: |
Sat, 25 Nov 2017 07:48:07 -0900 |
On Sat, 2017-11-25 at 07:06 -0800, Matt Wette wrote:
> > On Nov 25, 2017, at 6:47 AM, Matt Wette <address@hidden>
> > wrote:
> >
> > you probably want named let
> >
> > ((_ n exp exp* ...)
> > (let loop ((n n))
> > (unless (<= n 0)
> > exp exp* ...
> > (loop (1- n)))
>
> but not a broken one
>
> ((_ n exp exp* ...)
> (let loop ((cnt n))
> (unless (<= cnt 0)
> exp exp* ...
> (loop (1- cnt)))))
>
I want both the looping and the expression evaluation to be happening
at run time. The target is to repeat the side effects of the
expressions n times, and the return values are irrelevant.
I think this last submission from Matt does exactly what I want, the
full version being
(define-syntax repeat
(syntax-rules ()
((_ n exp exp* ...)
(let loop ((cnt n))
(unless (<= cnt 0)
exp exp* ...
(loop (1- cnt)))))))
scheme@(guile-user)> (repeat 10 (display "la\n"))
la
la
la
la
la
la
la
la
la
la
The part that confuses me a little is why
(repeat 10 (display cnt))
doesn't break it. Must be that magical hygiene mentioned in the info page.
--
https://worldenglishbible.org/
signature.asc
Description: This is a digitally signed message part