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: cond clause does not allow definitions Date: Thu, 23 May 2024 00:34:22 +0200 Message-ID: References: <20240523001202.SNC02C00D1JCEDt06NC2dB@albert.telenet-ops.be> 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="22155"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Maxime Devos Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu May 23 00:35:17 2024 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 1s9uYH-0005TT-9j for guile-user@m.gmane-mx.org; Thu, 23 May 2024 00:35:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9uXm-0000X6-H0; Wed, 22 May 2024 18:34:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9uXf-0000WV-5T for guile-user@gnu.org; Wed, 22 May 2024 18:34:39 -0400 Original-Received: from mail-vk1-xa29.google.com ([2607:f8b0:4864:20::a29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9uXc-0006HB-IK for guile-user@gnu.org; Wed, 22 May 2024 18:34:38 -0400 Original-Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-4e4e4e5414dso90963e0c.2 for ; Wed, 22 May 2024 15:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716417275; x=1717022075; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Amy4yaNeKVnbkp9AD0x2Thrm0nAJQCOiCQgeePXctb4=; b=FHI+KjLcuhAm/zmAsLUAU2JnIaomhu19gOcCbCqjFS/oFFCC+5WH60uSCYeQ6BWUQ6 cZo1Kai6/65qkbpIVPwTw1+l3C+5WK04auClCLEe7lJ6KTspkBLf7U4RAvZhUpXtwENn C0ZEalHBPfWDIOn5K/PaZqI7fWRXd7iBq2Jvn/9BMhfdYs51Oso7/eKL9Ez1/PHxnx+4 LVP+jhZa4uAOv/184VIY3rJZGZ+DucRhbMT8rNHuiauGwIPifn+PB5m4wH+0E2CYV3LA 7Syu/jjsXwSXZ7FFqNZ/xahCzIm5CYlrwcmRtnSRExY3rhXEa/h52PXiW6mF7nYq+YSG NrJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716417275; x=1717022075; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Amy4yaNeKVnbkp9AD0x2Thrm0nAJQCOiCQgeePXctb4=; b=cZ/LewToOVTwyMxP8xfLWxF6qopIUVZNwTabkBiyHxk562RlylJSSU4GGZw+jwzts3 SC/p0bdAVaF5EmoouMLVIrH3M4nPujoZiBLQYGxLNri5h7jCU4vFFQaK0sSlKDhnm0Zo qoYB2qptxBvfVEtVzLKaDCitcUU9+gEe1rZiyy21WhJc5pbdmteal6dIojYJavz8cX0c F5ibnRW8D1L2o1BMBihDpc5MUTk1KSUurAKt/9h04p1QFXrhsMqqyAwcYgzAHSfMY9Sb zFnw8A35IFvjKyZVEi54pkUzKbRQPAqtbfJRvj9+7Nq9oA9PHegrejBcg/rC4FU2WU7g Vglg== X-Gm-Message-State: AOJu0YzcsdUBtTC05iaWLyCvkr++jqwuSYcvBmDnD11xRqWeFSSPbvdF QXfwavUXGgQOuIgIeWVUzCMnRwgF1ImikWIbLe01LoyVQj9CDD+xImx3yQ6G2IErxmEbk8sdBer zrrr24fNNwJQ2V/aMC90o0d1+P0bG9zP+ X-Google-Smtp-Source: AGHT+IGz6fx8PQKTEfcRT2alRPBJOnxjyZBI9y007LwrkzR33Xi5XBP82pQKTy/Wft9P19/sKIKv130KSkjuh5U7EVY= X-Received: by 2002:a05:6122:9aa:b0:4df:235b:8ba1 with SMTP id 71dfb90a1353d-4e218522418mr3537949e0c.7.1716417273714; Wed, 22 May 2024 15:34:33 -0700 (PDT) In-Reply-To: <20240523001202.SNC02C00D1JCEDt06NC2dB@albert.telenet-ops.be> Received-SPF: pass client-ip=2607:f8b0:4864:20::a29; envelope-from=damien.mattei@gmail.com; helo=mail-vk1-xa29.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 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19683 Archived-At: hello Maxime, On Thu, May 23, 2024 at 12:12=E2=80=AFAM Maxime Devos wrote: > >but it is allowed in else clause: > > >scheme@(guile-user)> (cond (else (define x 7) x)) > > >$4 =3D 7 > > > > > >not really logic > > > > Probably in the implementation of =E2=80=98cond=E2=80=99, (cond (else X))= reduces to =E2=80=98X=E2=80=99. > > > > It=E2=80=99s tricky to ensure the same behaviour here as is the case when= there is > more than only the =E2=80=98else=E2=80=99 clause =E2=80=93 without tail-c= alling, you could use > =E2=80=98call-with-values=E2=80=99 in the macro to artificially make an e= xpression context > etc., but =E2=80=98cond=E2=80=99 needs to tail-call for X. > > > > If someone wishes to implement this, I would propose defining some new > syntax =E2=80=98begin-expression=E2=80=99 (like =E2=80=98begin=E2=80=99, = but instead of splicing, it > interprets things as a bunch of expressions to evaluate in-order, and wit= h > the last expression in tail-position). Would probably be needed to be > implemented as a primitive. > > > > Then, =E2=80=98(cond (else X))=E2=80=99 could be implemented as (begin-ex= pression X). > > > > The documentation complains a bit about how =E2=80=98begin=E2=80=99 does = both splicing and > this =E2=80=98begin-expression=E2=80=99, but 'begin=E2=80=99 can be split= ! (At least, I think so, > it has been a while since I read that part.) > > > > >It is allowed in Kawa and Racket but they are not scheme references > > the R5RS and R7RS talk about 'clause' without more information > > > > I don=E2=80=99t know what the standard says about this. > > > > >is it normal for Guile to consider clause for cond to be an expression > > context and not a definition context? > > > > Personally, I don=E2=80=99t care whether something is =E2=80=98normal=E2= =80=99, whatever that=E2=80=99s > supposed to mean. What I would care about, is whether the implementation > matches the documentation, whether the documentation is complete (even > saying =E2=80=9CIt is unspecified whether [this] or [that].=E2=80=9D woul= d suffice) and > whether the (documented) semantics is desired, useful, convenient and > consistent with relevant standards and conventions. > > > > In this case, not all of these are satisfied. > > > > >should not be better to consider definition context? that would allow mo= re > > possibilities. > > > > That would be possible =E2=80=93 (cond (a x) ...) could be interpreted as= (cond (a > (let () x)) ...) instead. > > > > However, I don=E2=80=99t think it has the semantics you desire. Some time= ago, you > asked questions along the lines of making a macro =E2=80=98define-block= =E2=80=99 that > allows doings things like > yes... i had written a special form condx that allow both inner definition and inter-definition between conditionals LOL (do not scream please... :-) : (define-syntax condx (syntax-rules (exec else) ((_) '()) ;; allow no else clause ((_ (else e ...)) (let () e ...)) ((_ (exec s ...) d1 ...) (let () s ... (condx d1 ...))) ((_ (t e ...) tail ...) (cond (t (let () e ...)) (else (condx tail ...)))))) > > (define (f) > > (if blah > > (define-block foo 1) > > (define-block foo 2)) > > [do things with foo here]) > > > but that=E2=80=99s not how scoping, macros and in particular =E2=80=98let= =E2=80=99 works in Scheme, > as mentioned there. > > > > Personally, I think implementing =E2=80=98cond=E2=80=99 as the cond+let s= tuff mentioned > above is a bit risky w.r.t. misunderstanding scoping, consider for exampl= e: > > > > (define (f x) > > (define y x) > > (cond ((square? x) (define y (sqrt x)) (pk =E2=80=9Ctook a square root= =E2=80=9D)) > > [more branches here]) > > y) > > > if i understand , one could misuse y , but it is clear for me that the y in cond is different than the one more global in f and the last y and result of f should be x , it is to the programmer to take care of that. consider Python , it is incredible : if True: x=3D7 x 7 and now x is defined out of the branch of x not a problem for me with that. Regards, Damien > which would silently do the wrong thing (unless you enable warnings for > shadowing, but you can do neat things with shadowing =E2=80=93 you can wr= ite pure > code in a somewhat imperative style (*)). > > > > Best regards, > Maxime Devos > > > > (*) See, e.g., > https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/config/parser.sc= m, > where =E2=80=98let^=E2=80=99 can do (if X (return Y)) and =E2=80=98contin= ue=E2=80=99 without let/ec (not an > use of shadowing but sounds like something you may be interested in). On > line > https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/config/parser.sc= m#n481 > and 485, you can see how shadowing is used as a replacement of mutation. >