From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Abou Samra Newsgroups: gmane.lisp.guile.user Subject: Re: macro definition for continue and break Date: Sun, 4 Sep 2022 13:13:52 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40109"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Cc: Guile User To: Damien Mattei Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 04 13:15:18 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 1oUnaw-000AG2-IL for guile-user@m.gmane-mx.org; Sun, 04 Sep 2022 13:15:18 +0200 Original-Received: from localhost ([::1]:41076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUnao-0005k8-Sk for guile-user@m.gmane-mx.org; Sun, 04 Sep 2022 07:15:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUnaQ-0005jS-9K for guile-user@gnu.org; Sun, 04 Sep 2022 07:14:46 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.10]:57751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUna2-0000ZD-6w for guile-user@gnu.org; Sun, 04 Sep 2022 07:14:23 -0400 Original-Received: from [172.20.10.4] ([37.167.14.149]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.184]) with ESMTPSA (Nemesis) id 1N0F9t-1pGsOb1TxX-00xIzz; Sun, 04 Sep 2022 13:14:19 +0200 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:ikaysUAjR8y81s0K9mJxqIb++4WPAJoG3H5emnATiMpQqVsUrh7 QyagJYJ214fDkv2rx9K66Vmlt5BRfUdlMasa/JMkmbAq49nqCdBWwJv6eBkQxqXk0EUycOU wDaHJiFnAxpTBbO6Jy6GYyFIgzM2uDfT0ODKBnPxCB2PwRLDw6FeDnPnCIwbLKblzwMUeKF WrxjdliDOJ+JyREXGv1NA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Xkd6rrLsq20=:ZReveKui2f7DzyuP6u4lQu gbYXfO8hU+2vlHlwLgIHgv+H5ZSg5TdD7CnKj4oAzXKimsLSj7KeGWFggARM16vnDandZ9DnA VHu1BDC2tvXGq2JO3J75buayUjhzqoup5yDk4lDJNaSOxp0/0i2gLWg1PYTENYQR3cHC0XbY/ z4E6BCRx5GuFcliehaAC07jfnRFLU5uOCmsBpdNShxt/BHO8GWrO02guPbME1RAsMZVuesGeK edTx/MrWfxZBHARm/N/Vc9r2qWBaIVSStRqLlbKUwYumwPzoYwFcF2TRhXDi7JMlnvuaJU09Q xlFCk0E+wZjknmowiAIsylCJRtY73S3Mz41YgMDCtvPsYobaMsRSpSSx8hVwwidF6SbaGPGDL ZBpgR6eWTkPr9puqK11DU6lZpuqH50wplifYwL5Sk9hE+Vr+nnxr+ZFREseiziAZoelL7dCI+ eAKmqyqpFL9oWtda60VoXJ7Rgze6JsajeTz6wvjWuU/d5i2wKz7bXoT2mggFB5imzUsaDljbZ /eBo3tY3u+6pItyshMipktE/RYrWit5MAPt8pbovhuzygMpLMhzZKOk77AnBCmIvZ4ZasMIpg Cx6SRRDWceXYIynP5qgbfAVwO9mUZeApPvJo7bGpnaHd3oeooJTSpDZ0B4oo3LlrF2BWoVdmo Z/FOjyuE3csh8m9gGfobJyMoe+PNjvxKXz4X66wwX/PlQNNy866pPA2IKrGVEnwEqbTH1VD8N SCVG5xScuu862Yc5vyBeHAXMp7Zgl3MJBUiiEo2P8s5IkmjgCG3lmVkEODxkEFU3zKDue5tb Received-SPF: none client-ip=212.227.17.10; envelope-from=jean@abou-samra.fr; helo=mout.kundenserver.de X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.978, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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:18565 Archived-At: Hi, Adding back the list in CC. Le 04/09/2022 à 12:49, Damien Mattei a écrit : > 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… ? > 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-step.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