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: escaping from a recursive call Date: Wed, 9 Nov 2022 18:18:39 +0100 Message-ID: References: <8735asoytw.fsf@laura> 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="38965"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Nov 09 18:19:34 2022 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 1osoje-000A1m-Aa for guile-user@m.gmane-mx.org; Wed, 09 Nov 2022 18:19:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoj1-0004gq-HQ; Wed, 09 Nov 2022 12:18:55 -0500 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 1osoj0-0004gS-8o for guile-user@gnu.org; Wed, 09 Nov 2022 12:18:54 -0500 Original-Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1osoiy-0005YV-Hs for guile-user@gnu.org; Wed, 09 Nov 2022 12:18:54 -0500 Original-Received: by mail-ej1-x62f.google.com with SMTP id f5so48615180ejc.5 for ; Wed, 09 Nov 2022 09:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=VgTq+kkT7FDcHb95toI4THb/+UKxoODQKV0kvJXGkuM=; b=lfqkwYq1ohTRokLgtEP47GUHh8chwBhuj5ZK1u6a5wG7P+CK/7c7LnB+nTElF7oxgX rastv7Dv/WwQCf4cS4Egrxg5zRWQLf8ksswvAhgWFF5pmzD/Er0V4zSiQHUMuU04PyzY J7ubJ4rTBBdJ64qo7X4sY89zmb0XibCSe7Py6ER/hsRjnnkK1bGpRmlekkpfeRhqu+/i 59nnTXeVQuI+Cl9SNV8q+556lD7B5l70NWEf663PS6gbNfMIEdfnDf1Lfawt5BTzQpi7 Kd6u3sXG0tlE+kr9WL4hZMeHplYHNu3skT3wkIlaerFG/qa9pWvBj0cHiPJjlL+i5jjR D+PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=VgTq+kkT7FDcHb95toI4THb/+UKxoODQKV0kvJXGkuM=; b=18LydckFKimyxPx+q9n91T0KDd81HnnXBq2ltksHxe5O+2nWAlvNyHMAc1IGDf3k6N lJ7b+UtCxo9VYoEuFe0JfGkAzlOv8HSE1tncXBVsVvx7LOTZSgHiUBrGW0/gcfs/2Bqo g0z54y8sqg3WCg+rYLWrfYo1kQYI3pMNWCwEYPlbsfyI/z/r74anglz0BwpRIkGZFVUg PZ3UUBRuth8EOqwvc7YXRu0Y9qUs9RHJniGLZsVv6ETcbUqtESHkIPzWEyQHxq2jxOfK b+kOcBGNRuK6r4W3TEfsxi3zlIe3REl4QqSfiZWzMCZ1BU9ue+qKYPL6XWutetPtVmb7 LBPA== X-Gm-Message-State: ACrzQf0P8MkMvKrzJ64ONor5LXNhRrTNI/dpmZppV4hiFEZ4WKFDxkCX A0rJvOplInP6ZQCTRy5Iq9ZJmfIMpO45iSNITEACNgNG X-Google-Smtp-Source: AMsMyM66yl35Dq7F36w3FHDwdXGw6j+6fnH2JDxubSVXCBbdOMzLXfyYGPopf0abm86lGB0FndR+2Pzrw6FM2FRcan0= X-Received: by 2002:a17:907:783:b0:76e:f290:8b5 with SMTP id xd3-20020a170907078300b0076ef29008b5mr58777558ejb.395.1668014330657; Wed, 09 Nov 2022 09:18:50 -0800 (PST) In-Reply-To: <8735asoytw.fsf@laura> Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x62f.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:18702 Archived-At: but in the general case , i want a macro that can do it on any function (i'm not sure it can be done because the continuation have to be captured just before the call to the function and be inlined at the good place....) On Wed, Nov 9, 2022 at 5:52 PM Olivier Dion wrote: > On Wed, 09 Nov 2022, Damien Mattei wrote: > > i need a way to escape not only the current call of a recursive function > > (it is already done) but alls: > > > > example: > > > > (def (foo n) > > (cond ((= n 0) 'end0) > > ((= n 7) (return 'end7)) > > (else (cons n (foo {n - 1}))))) > > Is that what you want? > --8<---------------cut here---------------start------------->8--- > (use-modules > (ice-9 control)) > > (define (foo n) > (let/ec return > (let loop ((n n)) > (cond > ((= n 0) 'end0) > ((= n 7) (return 'end7)) > (else > (cons n (loop (1- n)))))))) > > (pk (foo 5)) > (pk (foo 10)) > --8<---------------cut here---------------end--------------->8--- > > -- > Olivier Dion > oldiob.dev >