From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Repeat syntax Date: Sat, 30 Dec 2017 14:18:35 +0100 Message-ID: <87fu7s5p78.fsf@gmail.com> References: <1511586326.26826.3.camel@qlfiles.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1514639837 31402 195.159.176.226 (30 Dec 2017 13:17:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Dec 2017 13:17:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) Cc: Guile User Mailing List To: Christopher Howard Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Dec 30 14:17:13 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVH0d-0007c4-GF for guile-user@m.gmane.org; Sat, 30 Dec 2017 14:17:12 +0100 Original-Received: from localhost ([::1]:54233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVH2Z-0004yu-C3 for guile-user@m.gmane.org; Sat, 30 Dec 2017 08:19:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eVH28-0004yR-D7 for guile-user@gnu.org; Sat, 30 Dec 2017 08:18:41 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eVH27-00050X-Bp for guile-user@gnu.org; Sat, 30 Dec 2017 08:18:40 -0500 Original-Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]:33680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eVH27-0004z0-4c for guile-user@gnu.org; Sat, 30 Dec 2017 08:18:39 -0500 Original-Received: by mail-wr0-x236.google.com with SMTP id v21so32823766wrc.0 for ; Sat, 30 Dec 2017 05:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=wmMLs6tyQ9Bk56joZKzO71tAR0CRkncn+b8gi7Nb9fs=; b=N+wpIFfQpf3X0b4KTphvjtHRP6Sngw+L+BdimlbTClApg2He9WHZxwpdoRBYzkn+hj MyX1nyVQM5E16MANchfkmq1T/+jmheibpFwSVHrqKXhM9TtopwOJJwsCHEcN5lmI1h38 5iryfD+zn5bTTCbh/DfmAATRXRIkSWG0zERHLTPHfIi47IvDdzo1+sESKA+4KQD+o0US 7TNFClCORVuj1YnCZKybpYlT4qowi73DV0zOXWsOGrwd/0fpyvWTuMRBhuoeED7kXlW6 bpB4qHItc8wGkCH3EBXA+qwBSe6VV02gFf6jtTuMAaK9oITzdhv2qDV0PavnR1oYaXOB N2Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=wmMLs6tyQ9Bk56joZKzO71tAR0CRkncn+b8gi7Nb9fs=; b=NsHaUBhdHo6XSHzP5FTZFHaAewHBMS5I/jZfDXyPCjOtQZsLAX8Fn4qGAxH6EZRRk/ YtBmBlCwzq+XCmD0IwM9sAZbuoSb3/xyn700wmBLreZYy3pZFkgTCOkO9E6hLQ/BbWBZ LSzXBaZd25016UT9G4vuyvoyIL4zJR1D0tBojO8NTUjYbqFTTlTQhDJkXVSsd61xELOT m6CmirDCXcmhiihtCMVUANZLsbE5VdPWk9eNJZiZycWRabEODs0SGhocF2URSo91jdcj KkAalGYWUVuL0UkKNoJQWWDXn3dQkH++dBTUd4vnQH2KBHRbWTdW8s5M69ObHIspeRR2 j3bg== X-Gm-Message-State: AKGB3mJu+Cid0DFbNIX1KMIdp0ydhfWoeIO2gUnZo7GZKNQGNgCL2QwO /BRnB1PXtWfxc2+ZP+iIaMtlIQ== X-Google-Smtp-Source: ACJfBotzVqOE2xNfEqGk7DOiYzr/lfGypbNbPCuylhdkZ7i9pLNslD2XIoDxBXeVFn/LJC+Vlwv4dQ== X-Received: by 10.223.178.87 with SMTP id y23mr33174869wra.23.1514639917689; Sat, 30 Dec 2017 05:18:37 -0800 (PST) Original-Received: from T420 ([2a02:908:c35:b420:da9d:67ff:fece:b3ad]) by smtp.gmail.com with ESMTPSA id u54sm7685394wrf.77.2017.12.30.05.18.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Dec 2017 05:18:36 -0800 (PST) In-Reply-To: <1511586326.26826.3.camel@qlfiles.net> (Christopher Howard's message of "Fri, 24 Nov 2017 20:05:26 -0900") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::236 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14391 Archived-At: Christopher Howard writes: > 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 > =C2=A0 (syntax-rules (repeat) > =C2=A0=C2=A0=C2=A0=C2=A0((_ n exp exp* ...) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0'(unless (<=3D n 0) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0exp > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0exp* > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0... > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(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=C2=A0either infinite expansion, or an important variable getting > overshadowed. So, could somebody point me in the right direction? The 'do' syntax, although difficult to get used to, can do this: (do ((times 10 (- times 1))) ((zero? times)) ) Here's the specification of 'do': (do (( ) ...) ( ...) ...) The metasyntax "x ..." means ZERO or more occurrences of x. Evaluation rules: 1. The and pairs are bound as if in a 'let'. 2. The is evaluated: A. If true, the s are evaluated in order, the last result being the result of the 'do' expression. B. If false: a. The s are evaluated in order. b. The and pairs are bound as if in a 'let' (the previous bindings of s are available). c. Go to step 2. Taylan