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: Writing a procedure in different style Date: Sun, 13 Dec 2020 13:29:31 +0100 Message-ID: <33683c10-5e29-8e4a-03a4-64852fbcf474@posteo.de> References: <3760549b-b32f-fafc-1291-8e3eda7b3753@posteo.de> <2d6f348c-1e43-a5c4-1998-baa04b91bf8c@gmail.com> <1385bd6a-c14e-76f1-6dfe-4cf50d192375@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17575"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Icedove/68.10.0 Cc: Guile User To: Taylan Kammer Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Dec 13 13:30:07 2020 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 1koQVr-0004U6-M5 for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 13:30:07 +0100 Original-Received: from localhost ([::1]:37750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koQVq-0008AM-FG for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 07:30:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koQVP-0008A8-UH for guile-user@gnu.org; Sun, 13 Dec 2020 07:29:39 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:57021) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koQVN-0006Zg-4A for guile-user@gnu.org; Sun, 13 Dec 2020 07:29:39 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 7229B160060 for ; Sun, 13 Dec 2020 13:29:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1607862572; bh=hRb6nVkvzCFrmcuTRa2d5scEAWRU4qvxsl/JapY/Lvo=; h=Subject:To:Cc:From:Date:From; b=HvqDqtNcViat32OmYQoaH/U2dLD37s//hfpMTQTDD+i4Qdrzs7yJxQhN19VPUfB19 2mBwkOav/z5BbFmZWdINk1av1122+7z226JmZievSd2PNT39VGtUwp31rDMv2TN/RH FXsCuLMLd/QwCrbM1WZcR/C5pYXnpjjJphXSGn6miQnKhSVJjvX8Zdeqqu3vh0hPoi ZsHW2A94Bp/s8xvLlkGVjMilzNVPmjTWXfCcbynbwbz00e3FGxiXoMfiW9uD0WIkpw obQjNBfoazhSssc6t9ApDuSFl1asx0iAJwZ6LwNq7kqipD00CBlwe7muCw9D1IGPIi yGJ7JeTnjHxtQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Cv3k36MVqz9rxW; Sun, 13 Dec 2020 13:29:31 +0100 (CET) In-Reply-To: <1385bd6a-c14e-76f1-6dfe-4cf50d192375@gmail.com> 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, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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:17077 Archived-At: Hello Taylan! I tried your procedure and indeed it seems to work : ) I think what I had been missing before were 2 things: 1. I did not have the (if (null? rest) ...) parts, so I always tried to directly make a recursive call, perhaps wrapped into a cons, append or list. But if the rest was not null, then this would always add some level of nesting to my result, when it finally returned, which I did not want. The (if (null? rest) ...) part makes sure, that the empty list is given instead. 2. The fact that I could simply cons onto the rest, because the procedure works with arbitrarily nested lists anyway. Thanks for your input! Regards, Zelphir On 13.12.20 12:51, Taylan Kammer wrote: > On 13.12.2020 08:06, Taylan Kammer wrote: >> >>    (define find-in-tree* >>       (λ (peg-tree filter-proc) >> >>         (define traverse >>           (λ (subtree rest) >>             (simple-format (current-output-port) >>                            "working with subtree ~a\n" >>                            subtree) >>             (cond >>              [(null? subtree) >>               (if (null? rest) >>                   '() >>                   (traverse (car rest) (cdr rest))] >>              [(pair? (first subtree)) >>               (traverse (first subtree) >>                         (cons (cdr subtree) rest))] >>              [(filter-proc (first subtree)) >>               (cons subtree >>                     (traverse (car rest) (cdr rest)))] >>              [else >>               (traverse (cdr subtree) rest)]))) >> >>         (traverse peg-tree '()))) > > Correction, for third branch of the cond that didn't check if rest is > null: > >   (define find-in-tree* >      (λ (peg-tree filter-proc) > >        (define traverse >          (λ (subtree rest) >            (simple-format (current-output-port) >                           "working with subtree ~a\n" >                           subtree) >            (cond >             [(null? subtree) >              (if (null? rest) >                  '() >                  (traverse (car rest) (cdr rest)))] >             [(pair? (first subtree)) >              (traverse (first subtree) >                        (cons (cdr subtree) rest))] >             [(filter-proc (first subtree)) >              (cons subtree >                    (if (null? rest) >                        '() >                        (traverse (car rest) (cdr rest))))] >             [else >              (traverse (cdr subtree) rest)]))) > >        (traverse peg-tree '()))) > > > Taylan -- repositories: https://notabug.org/ZelphirKaltstahl