From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: Repeat syntax Date: Sat, 25 Nov 2017 15:21:37 +0000 Message-ID: <20171125152137.4ee1d267@bother.homenet> 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 1511623405 16499 195.159.176.226 (25 Nov 2017 15:23:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 25 Nov 2017 15:23:25 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Nov 25 16:23:20 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 1eIcIW-00030Y-0y for guile-user@m.gmane.org; Sat, 25 Nov 2017 16:23:16 +0100 Original-Received: from localhost ([::1]:53480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIcIU-0002X7-BZ for guile-user@m.gmane.org; Sat, 25 Nov 2017 10:23:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIcH4-0001PX-9n for guile-user@gnu.org; Sat, 25 Nov 2017 10:21:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eIcGz-0006mu-CB for guile-user@gnu.org; Sat, 25 Nov 2017 10:21:46 -0500 Original-Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]:36615) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eIcGz-0006mo-54 for guile-user@gnu.org; Sat, 25 Nov 2017 10:21:41 -0500 Original-Received: by mail-wr0-x236.google.com with SMTP id y42so22628785wrd.3 for ; Sat, 25 Nov 2017 07:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9SRDwpT2t7NgMd0/KWWFHcm+po71hcE4HTNzbmgILqY=; b=m8eirUMVTYOTTUfBAFdLT/Czyk6wIc7ihhmuAfWFU+iRafU6/p7XkhwDeorNlT9bNT 9kPrTvx3+9vcQH57cxRfypEtXtM+dnxonPM9hZCKGRLgY5eF2jY5TBi7IlUpKmLiKTzs aBFc+OBV+V1fq90RUDyzUpzVXzxKV3g5c54UrtT6Nw21lMzQT1Xs/9n438VWECOKYihJ fkGbaAtXdwm+uLH+pQPYhKNWoYrgvP/fMC8+IyaGCYFxE5Ke4ev+kritAfDnUGbPav3t x4QHBC0YAiNJhBdQSGqHDRbI35+alTgdALEyesclc2b+QdCf4HxQ0rNev6pPa2TwKYt3 AQEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9SRDwpT2t7NgMd0/KWWFHcm+po71hcE4HTNzbmgILqY=; b=GURSv1xAVpk28Kn8u8SRWtq+wUmPouJJ6C9w+t4H10SHHvb95RNbo/wBSpX8UXF48f BzZcn++ys0HTkaitHv8qps05q38uSiqIXyGwDf80vhpzrj3lqZpiif6emMmAWh9/5ejd BUBaKNCJfecnhOnkF4zV18K5KH3hp1NR9/PeAQSrtXrKFYSvgIUIn724f6ZhFfnkSV6w hL5qqGjOXVdkrhmzKH9WF6WDMfsVPSqsEDgHFyUQPafkwtGSpKGqkJUem3BRsNhZ41yR a/AjMLhldylWAKtfquNyWZ6MyHYk1XcNzH5KJHc00NTI6FMgjPR/fVorS5omxuWqscER zxlg== X-Gm-Message-State: AJaThX68RyLOJVjcwcfEzopFI14ZR8NIjV8t6xFdrVn3tWFgpcybH76j uAicpFhh9Xo+nJFc4+8537hD4Q== X-Google-Smtp-Source: AGs4zMZHJEPtDrJn3tGrSPxlUd+DJK0zUenHijSbtg70b3kaKkyWmyC3YAqvm984T9nvl+LY8uAYbA== X-Received: by 10.223.165.4 with SMTP id i4mr29112344wrb.158.1511623299558; Sat, 25 Nov 2017 07:21:39 -0800 (PST) Original-Received: from bother.homenet ([95.146.110.48]) by smtp.gmail.com with ESMTPSA id b45sm10429492wrb.1.2017.11.25.07.21.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Nov 2017 07:21:38 -0800 (PST) Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with ESMTP id C05E7260232 for ; Sat, 25 Nov 2017 15:21:37 +0000 (GMT) In-Reply-To: <1511586326.26826.3.camel@qlfiles.net> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) 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:14290 Archived-At: On Fri, 24 Nov 2017 20:05:26 -0900 Christopher Howard wrote: > Hi list, I want to have a function >=20 > (repeat n exp exp* ...) >=20 > 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 >=20 > (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* ...)))= )) >=20 > 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? You need to separate the looping, which occurs at compile-time, from evaluation of the expressions, which occurs at run-time. Here is one way of doing it, insofar as I understand what you want: (define-syntax repeat (lambda (x) (syntax-case x () [(_ n exp exp* ...) (let loop ([count (syntax->datum #'n)]) (if (< 0 count) #`(begin exp exp* ... #,(loop (- count 1))) #'#f))]))) (repeat 5 (display "exp0 ") (display "exp1 ") (display "exp1\n"))