guile-user
[Top][All Lists]
Advanced

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

Repeat syntax


From: Christopher Howard
Subject: Repeat syntax
Date: Fri, 24 Nov 2017 20:05:26 -0900

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/

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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