From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: macro definition for continue and break Date: Mon, 12 Sep 2022 21:19:42 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38364"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.7.0-alpha0-929-g09f3e68182-fm-20220908.004-g09f3e681 Cc: "Guile User" To: "Jean Abou Samra" , "Damien Mattei" Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Sep 12 21:20:39 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXoyz-0009nI-4V for guile-user@m.gmane-mx.org; Mon, 12 Sep 2022 21:20:38 +0200 Original-Received: from localhost ([::1]:50606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXoyy-0007mi-45 for guile-user@m.gmane-mx.org; Mon, 12 Sep 2022 15:20:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXoya-0007mJ-RW for guile-user@gnu.org; Mon, 12 Sep 2022 15:20:12 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:40615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXoyW-0000CE-J5 for guile-user@gnu.org; Mon, 12 Sep 2022 15:20:10 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F09705C0182; Mon, 12 Sep 2022 15:20:04 -0400 (EDT) Original-Received: from imap51 ([10.202.2.101]) by compute4.internal (MEProxy); Mon, 12 Sep 2022 15:20:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1663010404; x= 1663096804; bh=5z2/Xk6QFo5iBUAe0F15JDvvlUFKEkUNnHKCFJOBdQQ=; b=H 3RdheNG8G1mDLnRUmhNrXC5tb4LlDBoPadp+8svCkLGhOfYewNGKb25EFVAulrCS I9L8T/7VL3MYevlAow+iFBes0W5cfaTAocxkbvoedYcbyFhz9SUwrEsLCFPlDcH4 /3U19yTAzg+7+g30sAketpO7Q/7WpRhFBPIyGqC+T580Slly3+nscG+HQ5eF5XBg yJWZuVu+AxaNPusAv58IVcVt3aE9PmRHoExbjK9clJlCVRZSbHPPOcQkVQ5PiEiH SIzbvBAwfuPF4xxF51hPV3LZTKJilaQ7uUUFLI33cohljuCuCu1U0/Zmai4gfAEO DQ/1H3MPMP/4snlXTGPyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1663010404; x= 1663096804; bh=5z2/Xk6QFo5iBUAe0F15JDvvlUFKEkUNnHKCFJOBdQQ=; b=u BdnO0vwVbs56TZX/gEpFZP4GOZMeHzxBV0vSisRGVBeVwglyX5IQOhM22tVFZBtj rNsh6qi4gSdSmBVQufJ4L5gEtLm4mu+YA3A/I9GLKI3f3UoAv3q4ffg2ZRwMkGe/ khkb8FM3Z64UzKCnyT9achsiQxhmwIUgRkdBhzMp58uvfEj0TFcE1GBPWNaIdwy8 ZtaNY+pc9kE8cDoCflbDYuCrtDv5qHiul+KMR90VPWca8MirjQvIooE3qTs0Bsa6 XqcgRfYAn2mJ+Fock8xb/av5TerwyFHgYWlh6meoWWV0Ay6RmwdtLASpDoJ96mmJ TRJR+t4g2NgxLKu26Aw5g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeduvddgudeflecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgfgsehtqhertderreejnecuhfhrohhmpefn ihhnuhhspgeujhpnrhhnshhtrghmuceolhhinhhushdrihhnthgvrhhnvghtsehfrghsth hmrghilhdrshgvqeenucggtffrrghtthgvrhhnpefggfdutdegvdejteduieeltdeujeeh fedvkeffjeeifeevhfejgffgfffhtdehgfenucffohhmrghinhepshhrrdhhthdpghhith hhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomheplhhinhhushdrihhnthgvrhhnvghtsehfrghsthhmrghilhdrshgv X-ME-Proxy: Feedback-ID: i57f3436d:Fastmail Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 807F9B60086; Mon, 12 Sep 2022 15:20:04 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: pass client-ip=66.111.4.25; envelope-from=linus.internet@fastmail.se; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18584 Archived-At: If you want a bit more advanced looping you could have a look at my goof= -loop: https://git.sr.ht/~bjoli/goof-loop It currently does not support a break or continue clause, but adding one= should not really be a problem. A good thing is that it does not rely on mutation for anything except hi= gher order sequences, meaning it does not lead to the implicit boxing ov= erhead of set!, which is a good idea in loops since that quickly adds up. Best regards=20 Linus Bj=C3=B6rnstam On Sun, 4 Sep 2022, at 13:13, Jean Abou Samra wrote: > Hi, > > Adding back the list in CC. > > > Le 04/09/2022 =C3=A0 12:49, Damien Mattei a =C3=A9crit=C2=A0: >> hello jean, >> yes (thank you for your help) i'm a sorcerer's apprentice that always=20 >> push to later the understanding of literals in syntax-rules, but by=20 >> instinct i finally succeed in making works the weird thing :-) , here=20 >> is my macro definition now for a for with break and continue: >> >> (define-syntax for >> >> =C2=A0 (lambda (stx) >> =C2=A0 =C2=A0 (syntax-case stx () >> =C2=A0 =C2=A0 =C2=A0 ((kwd (init test incrmt) body ...) >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0(with-syntax >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((BREAK (datum->syntax #'k= wd 'break)) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (CONTINUE (datum->sy= ntax #'kwd 'continue))) >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=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=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=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=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (loop)))))))))= )) >> >> note the mysterious #,#' that save the day ;-) > > > For me, it works without it=E2=80=A6 ? > > >> and a few examples (in Scheme+) >> >> ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+=20 >> 7} (display x) (newline) (break)) >> ;; 7 >> ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+=20 >> 7} (continue) (display x) (newline) (break)) >> ;; scheme@(guile-user)> >> >> ;; (for ({k <+ 0} {k < 3} {k <- {k + 1}}) >> ;; =C2=A0 =C2=A0 =C2=A0(display k) >> ;; =C2=A0 =C2=A0 =C2=A0(newline) >> ;; =C2=A0 =C2=A0 =C2=A0(for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7} >> ;; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (disp= lay x) >> ;; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 (newline) >> ;; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (brea= k)) >> ;; =C2=A0 =C2=A0 =C2=A0(newline)) >> >> ;; 0 >> ;; 7 >> >> ;; 1 >> ;; 7 >> >> ;; 2 >> ;; 7 >> >> ;; (for ({k <+ 0} {k < 3} {k <- {k + 1}}) >> ;; =C2=A0 =C2=A0 =C2=A0(display k) >> ;; =C2=A0 =C2=A0 =C2=A0(newline) >> ;; =C2=A0 =C2=A0 =C2=A0(continue) >> ;; =C2=A0 =C2=A0 =C2=A0(for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7} >> ;; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (display x) >> ;; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (newline) >> ;; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (break)) >> ;; =C2=A0 =C2=A0 (newline)) >> >> ;; 0 >> ;; 1 >> ;; 2 >> >> https://github.com/damien-mattei/library-FunctProg/blob/master/for-ne= xt-step.scm >> >> it also works with imbricated loops in a natural way (but other=20 >> interpretation and implementation could be=C2=A0 done , C act like th= is ,i=20 >> think) >> but if it could be coded better i will use a better version > > > Yes, it can be done better; see my reply on the other thread. > > > Best, > Jean