From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.user Subject: Re: Writing a procedure in different style Date: Sun, 13 Dec 2020 08:06:53 +0100 Message-ID: <2d6f348c-1e43-a5c4-1998-baa04b91bf8c@gmail.com> References: <3760549b-b32f-fafc-1291-8e3eda7b3753@posteo.de> 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="37927"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 To: Zelphir Kaltstahl , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Dec 13 08:07:25 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 1koLTY-0009ks-PY for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 08:07:24 +0100 Original-Received: from localhost ([::1]:49684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koLTX-0005VD-KK for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 02:07:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koLTB-0005V0-9P for guile-user@gnu.org; Sun, 13 Dec 2020 02:07:01 -0500 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:35828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koLT8-0008Vc-Vk for guile-user@gnu.org; Sun, 13 Dec 2020 02:07:00 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id q22so419376eja.2 for ; Sat, 12 Dec 2020 23:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=tHfEv5PyFFxZKkqMkZd91GKqFzeuLeal7z/G7Xl/OJw=; b=CbDwWO8NyK3QXqM9rO6VcRKRLjhtvoEOG0Y0rapzXlAqWpMZKObS1i/C7XwjIM1Utv 81QiO1Y8kq8uT0YDAFCPBg8EJNVcY/qOb2lAaO/ZNWK3Hw2hALipaY2ePLJupiIak37s 0oNa8McNs1yj+qciHlXg9qeo0CWijJao0AI6AcNk828sc2Vf/sCuXcpFtsHuKdLezSpN Lt9ztAXz8s4ciBGCGoLrUNdca9A6PCxPGO1quB4O3VBpbldUmwkYMwoZn2Ny1AuGqRWX WS9mTUXSK3Ug/cwat4+PTAdu3uc8fv7LxBEa/7etQ6EF0ddu++gIeYzo1HFS6l8+2zH0 rf4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=tHfEv5PyFFxZKkqMkZd91GKqFzeuLeal7z/G7Xl/OJw=; b=RIickCiqPnVpYaCOB4WqYTUEQN8+EORRwMZZJZNDBqunlSdQ8fRM91i//OqNEo0NfA RR3dIFsFzD1KQyY6pAhQ2aotLbbGfNt/aDZuxRlDZGHIjmbB9o97Qe15VPJA8MSvlTyg +Zl9W4cA/IWOWq1p0RiIJ9HQaw2zun1oMVQUOO1YzRxGEqDrUZxsdPiQd0FNwY4iLd3/ ew2DM/EysIkxP/axJaShylY+XH2JV3Cky+HIM+/vLuAWsYXcaZX9HiiVp7vzNzvt3q/t 9+ipGavTgzlTmKOOECNaLhYfg4fqPYw217Eh2r63bVLIN9su+/TrVWUQ5Fyc+OIyj31r b9cA== X-Gm-Message-State: AOAM530RYSTGMv2j8M23aIKaBk4iIoJiDAI/5CwU8vdDUT/nyjzutuQ/ 9ase6CXGhOANDgk2LKTSDJ2aqC4ggvRqWg== X-Google-Smtp-Source: ABdhPJy8HU5ViAKIgBdNZisGguzOxwWw6oey6juHZbUWVlXMsQDXtz+YeVeych0+hOU4zzFJ0VkT2w== X-Received: by 2002:a17:906:85cd:: with SMTP id i13mr17780326ejy.553.1607843216659; Sat, 12 Dec 2020 23:06:56 -0800 (PST) Original-Received: from [192.168.178.20] ([109.90.125.150]) by smtp.gmail.com with ESMTPSA id 3sm10932924ejn.7.2020.12.12.23.06.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 12 Dec 2020 23:06:56 -0800 (PST) In-Reply-To: <3760549b-b32f-fafc-1291-8e3eda7b3753@posteo.de> Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=taylan.kammer@gmail.com; helo=mail-ej1-x62b.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, NICE_REPLY_A=-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-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:17074 Archived-At: On 12.12.2020 13:22, Zelphir Kaltstahl wrote: > ~~~~ > (define find-in-tree* > (λ (peg-tree filter-proc) > > (define traverse > (λ (subtree cont) > (simple-format (current-output-port) > "working with subtree ~a\n" > subtree) > (cond > [(null? subtree) (cont)] > [(pair? (first subtree)) > (traverse (first subtree) > (λ () (traverse (cdr subtree) cont)))] > [(filter-proc (first subtree)) > (cons subtree (cont))] > [else > (traverse (cdr subtree) cont)]))) > > (traverse peg-tree (λ () '())))) > ~~~~ From what I can tell, the continuation argument is essentially used as a way of queuing up further work that is to be done. Adding an element is done by wrapping it in yet another procedure that adds some work, and popping an element is done by applying it. This means it should be possible to change it into an explicit data structure (e.g. simply a list). Here's an attempt, which I have not tested in any way: (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 '()))) In summary: - I rename 'cont' to 'rest' - I change (cont) to (if (null? rest) '() (traverse (car rest) (cdr rest))) - I change (λ () (traverse (cdr subtree) cont)) to (cons (cdr subtree) rest) - I change the initial seed of (λ () '()) to '() And I think theoretically it should behave the same. Taylan