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(itionals) with optional execution of statements Date: Sun, 12 Sep 2021 19:05:18 +0200 Message-ID: References: <6d4ff570-1b0c-8158-a236-a8c00102f7e4@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40283"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean-Paul Roy , Guile User , Damien Mattei To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 12 19:05:51 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 1mPSvO-000AGH-Lb for guile-user@m.gmane-mx.org; Sun, 12 Sep 2021 19:05:50 +0200 Original-Received: from localhost ([::1]:45770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPSvM-0006l9-LT for guile-user@m.gmane-mx.org; Sun, 12 Sep 2021 13:05:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPSv9-0006hy-DV for guile-user@gnu.org; Sun, 12 Sep 2021 13:05:35 -0400 Original-Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]:36776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mPSv5-0006M2-MF for guile-user@gnu.org; Sun, 12 Sep 2021 13:05:35 -0400 Original-Received: by mail-il1-x134.google.com with SMTP id v16so2829990ilg.3 for ; Sun, 12 Sep 2021 10:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=w1+862anc+czofv/t+Bi5MA0n9LkyiHAGcsgKdunVSE=; b=mIyKcPNRW9YTbw46QI87wdsKjqSpuirB/e2eW5SWr41Rfkx5V0wD04UEbMHdvLcthv 6ey1W1nUyGgba/3xres/2kKhWQFmobFAtGeV/IJJt5nnnwelS2PouOllykAfdC2xdcCE K3ThTp9IjWAx6gSuo9e/mDNKl6wzQ+23D+GBRc+XTNQRA8DIzULBAfw0wobJnz4qduuF nnlmQfFl68bVpvc43Kv6QD+8FWXp6Wr85tjfURqWbJ2cQJjX3T/xCtnuk2kDwRnN0F00 pHGU7D5KHXw6dYrm8XU03C24bRNrwq9V3hmXE1bPnrfM43R3jr0eiXtrL/Pug8sIq6/c Fcjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w1+862anc+czofv/t+Bi5MA0n9LkyiHAGcsgKdunVSE=; b=2q3l1ttVsGOfauavQqWKUzqBABTS7rAf3Ow49ygYM7K0XIrrRHlm0NfDlFQD/8gRUt SneUt66oJ3qr+MiTJOED92Usn8S/j09Ea9cHz2sCwf1rZEP4Zdo+HqStYLgcQFFMfhs+ FB4QR662AfhPdQ7OEZolb2+yMIxDubfBrIKwrGz5XUZo/KTmeCOCKNQvBXdNrxRqf54x zTqmSH/D/ZMyGzTC4HR4CMbCL19pUxy3GAvg5uR3hR+vI5unybcP9EjjQ+0q9E13rsmA W+au5SnPEjySek0Y6XU6XZKkGE+Wpqp8UQiKVUE8B/TP6UmduTFP19OqdBa8O0rbz0j1 APXQ== X-Gm-Message-State: AOAM530gYUGL/LtPfbz3oKabbW8cKoB4A4EnjzDAgcpIDXzpe4VfMeLZ eGzJjTnFvtRSecvW0ShoaJtKfNABk0YUaP1wufY= X-Google-Smtp-Source: ABdhPJx5clupdGytxypvO2/l1CtGZ7qpcm/D45ji9YEai8QuUjuOSvkB598unl2acbgkRohJoq2s76c1+ya7berRTTM= X-Received: by 2002:a05:6e02:f91:: with SMTP id v17mr5570336ilo.0.1631466329873; Sun, 12 Sep 2021 10:05:29 -0700 (PDT) In-Reply-To: <6d4ff570-1b0c-8158-a236-a8c00102f7e4@posteo.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=damien.mattei@gmail.com; helo=mail-il1-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 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:17728 Archived-At: Hello Zelphir, condx evaluate all code(s) in the 'exec' block until a conditional is true, it then evaluate the consequent code of course. So ,yes your true it saves a lot of nesting parenthesis as in this example: here a code with condx and without it: (define (ssigma-proto-condx L t) (set! cpt {cpt + 1}) (define ls (length L)) (define dyn (array-ref dyna ls t)) ;; dyna[ls][t] means 0: unknown solution, 1: solution found, 2: no solution (condx [(not (zero? dyn)) (one? dyn)] [(null? L) (array-set! dyna 2 ls t) #f] ;; return #f [exec (define c (first L))] ;; c is the solution [{c = t} (array-set! dyna 1 ls t) #t] ;; return #t [exec (define R (rest L))] ;; continue searching a solution in the rest [{c > t} (define s (ssigma-proto R t)) (array-set! dyna (one-two s) ls t) s] ;; return s ;; else : ;; c < t at this point ;; c is part of the solution or his approximation ;; or c is not part of solution [else (define s {(ssigma-proto R {t - c}) or (ssigma-proto R t)}) (array-set! dyna (one-two s) ls t) s])) without condx: (define (ssigma-proto L t) (set! cpt {cpt + 1}) (define ls (length L)) (define dyn (array-ref dyna ls t)) ;; dyna[ls][t] means 0: unknown solution, 1: solution found, 2: no solution (cond [(not (zero? dyn)) (one? dyn)] [(null? L) (array-set! dyna 2 ls t) #f] ;; return #f [else (let [(c (first L))] (if {c = t} ;; c is the solution (begin (array-set! dyna 1 ls t) #t) ;; return #t ;; else (let [(R (rest L))] (if {c > t} ;; continue searching a solution in the rest (let [(s (ssigma-proto R t))] (array-set! dyna (one-two s) ls t) s) ;; return s ;; else ;; c < t at this point ;; c is part of the solution or his approximation ;; or c is not part of solution (let [(s {(ssigma-proto R {t - c}) or (ssigma-proto R t)})] (array-set! dyna (one-two s) ls t) s))))) ] )) there a lot more of indentation and nesting. Note also that the use of let () in condx definition allow to use define in consequent and 'exec' block. Damien On Sun, Sep 12, 2021 at 11:41 AM Zelphir Kaltstahl < zelphirkaltstahl@posteo.de> wrote: > 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 > >