From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: macro definition for continue and break Date: Tue, 13 Sep 2022 16:16:49 +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="13338"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean Abou Samra , Guile User To: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Sep 13 16:21:38 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 1oY6nB-0003GO-GK for guile-user@m.gmane-mx.org; Tue, 13 Sep 2022 16:21:37 +0200 Original-Received: from localhost ([::1]:36156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oY6nA-00044j-DL for guile-user@m.gmane-mx.org; Tue, 13 Sep 2022 10:21:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oY6in-0001lr-M8 for guile-user@gnu.org; Tue, 13 Sep 2022 10:17:05 -0400 Original-Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]:44682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oY6ik-00051D-Qy for guile-user@gnu.org; Tue, 13 Sep 2022 10:17:05 -0400 Original-Received: by mail-lf1-x134.google.com with SMTP id i26so20328838lfp.11 for ; Tue, 13 Sep 2022 07:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=yetRQ8X+/98YnFJNq/FLZoVUl2JujECgdA7f1fKOuJw=; b=kmHjA/Rk9D8KyK0dJleQ509syuAzg6B5oRYlEcwh5116XY9Rtc8FzV/m8+xbaQ8vEr NvhpdNGA7QVNUfq9T067cBeiz3qHHpGrCPGfhxWwt9t6jL/25EH1c4mTglH/iD5bPiwR wn8Xg6otJnsCD7QcxbuOEuLTuCTojX2gDnPzSIHH3lbZJttyBXkT77dS6UYE6WefzoRX 5UlX/OyUFUdwt6NQysMpWAqhzWg+4VhzXlmPVZQjo8NbYq4AAXeZX86TOCv2oYnRyKxC HYc+VsmZ2r5iXERDcPdvWvA/7SB0x0RdW2nAfu7w4qgReHNgHjRW6N89PMYXDfEpakY8 iyGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=yetRQ8X+/98YnFJNq/FLZoVUl2JujECgdA7f1fKOuJw=; b=KYUjA1MZL/RFlIcKN+z4AyA/I7El/PPA4WGABWQqSiHGKjdEoMx7nbU/5Ccb2MFDKJ nwylgcqX22bkJOGhwhwzqJLIK2xudXav5BXGNdqvZPya93x5ISlsiuFYn1R2RmKscTbo NMoebmHAfbdaEdOFD5d9wETF4b5Bk2TSS/XrYtuvMZLWsV/9iha+rRZ6hU1+Sm3K1ksV cSVTth1xiEj5nIyMLPto6IFV/6kV2jAoLET3//11F/C2fcX0pH10AWSpVdC6O0h7OA0k kHaOdQLHKejSs8YdRWO9Phe1tWfcxos4KUVL3RR//vKr0qJHRHqs4OgIuaB3zsQNWH+4 hJuQ== X-Gm-Message-State: ACgBeo3dINR4tSAMc/A31vAtVUecAjOBrNQJS3WqV+hvqdnvEWNqOZSY qRVDlmHvvynFlCab4q7Pp5CGGMK1izqNkDjdXx4= X-Google-Smtp-Source: AA6agR4jebHzm2YOqNlA+e7lzKqVGf1Abck5zfYn8CXsUG2caSAjEWbacJF9RSa1gu8xKJddj3dqR6HTXceimPHaNv8= X-Received: by 2002:a05:6512:3d16:b0:498:f04f:56cf with SMTP id d22-20020a0565123d1600b00498f04f56cfmr9359644lfv.612.1663078620554; Tue, 13 Sep 2022 07:17:00 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=damien.mattei@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:18588 Archived-At: interesting , i was just intending to have syntax and features a bit like C in fact.Your syntax goes beyond, Racket for too, i do not know Chibli scheme. Regards, Damien On Mon, Sep 12, 2022 at 9:20 PM Linus Bj=C3=B6rnstam wrote: > 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 > higher order sequences, meaning it does not lead to the implicit boxing > overhead of set!, which is a good idea in loops since that quickly adds u= p. > > Best regards > 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 : > >> hello jean, > >> yes (thank you for your help) i'm a sorcerer's apprentice that always > >> push to later the understanding of literals in syntax-rules, but by > >> instinct i finally succeed in making works the weird thing :-) , here > >> is my macro definition now for a for with break and continue: > >> > >> (define-syntax for > >> > >> (lambda (stx) > >> (syntax-case stx () > >> ((kwd (init test incrmt) body ...) > >> > >> (with-syntax > >> ((BREAK (datum->syntax #'kwd 'break)) > >> (CONTINUE (datum->syntax #'kwd 'continue))) > >> > >> #`(call/cc > >> (lambda (escape) > >> (let-syntax > >> ((BREAK (identifier-syntax (escape)))) > >> init > >> (let loop () > >> (when test > >> > >> #,#'(call/cc > >> (lambda (next) > >> (let-syntax > >> ((CONTINUE > >> (identifier-syntax (next)))) > >> body ...))) > >> > >> incrmt > >> (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 <+ > >> 7} (display x) (newline) (break)) > >> ;; 7 > >> ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ > >> 7} (continue) (display x) (newline) (break)) > >> ;; scheme@(guile-user)> > >> > >> ;; (for ({k <+ 0} {k < 3} {k <- {k + 1}}) > >> ;; (display k) > >> ;; (newline) > >> ;; (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7} > >> ;; (display x) > >> ;; (newline) > >> ;; (break)) > >> ;; (newline)) > >> > >> ;; 0 > >> ;; 7 > >> > >> ;; 1 > >> ;; 7 > >> > >> ;; 2 > >> ;; 7 > >> > >> ;; (for ({k <+ 0} {k < 3} {k <- {k + 1}}) > >> ;; (display k) > >> ;; (newline) > >> ;; (continue) > >> ;; (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7} > >> ;; (display x) > >> ;; (newline) > >> ;; (break)) > >> ;; (newline)) > >> > >> ;; 0 > >> ;; 1 > >> ;; 2 > >> > >> > https://github.com/damien-mattei/library-FunctProg/blob/master/for-next-s= tep.scm > >> > >> it also works with imbricated loops in a natural way (but other > >> interpretation and implementation could be done , C act like this ,i > >> 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 >