From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: cond(itionals) with optional execution of statements Date: Sun, 12 Sep 2021 09:41:21 +0000 Message-ID: <6d4ff570-1b0c-8158-a236-a8c00102f7e4@posteo.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27594"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Damien Mattei Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 12 11:41:42 2021 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 1mPLza-00073R-NA for guile-user@m.gmane-mx.org; Sun, 12 Sep 2021 11:41:42 +0200 Original-Received: from localhost ([::1]:51096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPLzZ-0001Ks-Fl for guile-user@m.gmane-mx.org; Sun, 12 Sep 2021 05:41:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPLzN-0001KV-RN for guile-user@gnu.org; Sun, 12 Sep 2021 05:41:29 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPLzL-00044S-Kj for guile-user@gnu.org; Sun, 12 Sep 2021 05:41:29 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 1715D240029 for ; Sun, 12 Sep 2021 11:41:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1631439683; bh=Ji0zVab3IsbnLyYQK0o582OV3ITdsm4hYflgTM47na8=; h=Subject:To:From:Cc:Date:From; b=sJVJb23Pj2HRMPMckHfTuTewQHAVEG8piHsM1yiC4+H1hiXZEPbNiRziqQcB6jjgH Vx/M5FIoI0/Zac281p+KKwVolJ63nZ5p/J/unSnlWwetMuMn3Q/oq8sRDz2r31JiNe X6oHZPqcXPTrhx4Z3HuXhbORICvyZAgqSxgfw3HnhOedVE3Yg2/VVrZDWyfv5jaLqP azlhM4OAjLtYQnkUMChmKGGds8zTTOY7BOluDe6wmwIUFBRc4Z8m16gqDXRWI6owgq OsBomv5xLsUAhJ3XG1mVKjRhqcJlHNhsqE4YCEHnH+vog6Xs4VrvDBAklYWpV0lZSq k2oAlRpKta3JA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4H6l422bcQz6tmF; Sun, 12 Sep 2021 11:41:22 +0200 (CEST) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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:17727 Archived-At: Hello Damien! I am not sure I understand the reasoning behind condx: I think cond is already a macro, which only evaluates a consequent, if the predicate of its case is #t. Additionally multiple expressions are possible in each branch. To clarify, I ask: What is the case, where condx does or does not evaluate some code, when cond would not or would? Or is it rather about the different nesting / sequence of expressions, which condx seems to enable? I think the flow you demonstrate might save a bit of nesting. Best regards, Zelphir On 9/11/21 11:14 AM, Damien Mattei wrote: > hello, > > i wrote a little macro (file condx.scm) that allow : cond(itionals) with > optional execution of statements before: > > (define-syntax condx > (syntax-rules (exec) > ((_) > (error 'condx "No else clause")) > ((_ (else e ...)) > (let () e ...)) > ((_ (exec s ...) d1 ...) > (let () s ... (condx d1 ...))) > ((_ (t e ...) tail ...) > (if t > (let () e ...) > (condx tail ...))))) > > use it like that: > > mattei@macbook-pro-touch-bar library-FunctProg % guile > GNU Guile 3.0.7 > Copyright (C) 1995-2021 Free Software Foundation, Inc. > > Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. > This program is free software, and you are welcome to redistribute it > under certain conditions; type `,show c' for details. > > Enter `,help' for help. > scheme@(guile-user)> (load "condx.scm") > ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 > ;;; or pass the --no-auto-compile argument to disable. > ;;; compiling /Users/mattei/Dropbox/git/library-FunctProg/condx.scm > ;;; compiled > /Users/mattei/.cache/guile/ccache/3.0-LE-8-4.5/Users/mattei/Dropbox/git/library-FunctProg/condx.scm.go > scheme@(guile-user)> (define x 1) > > (condx ((= x 7) 'never) > (exec > (define y 3) > (set! x 7)) > ((= y 1) 'definitely_not) > (exec > (set! y 10) > (define z 2)) > ((= x 7) (+ x y z)) > (else 'you_should_not_be_here)) > $1 = 19 > > i share it to have idea about critics or idea to improve it as it will be > part of a Scheme extension to scheme language that will include other > features.... > > have a good day > > Damien -- repositories: https://notabug.org/ZelphirKaltstahl