From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: escaping from a recursive call Date: Thu, 10 Nov 2022 12:32:44 +0000 Message-ID: <20221110123244.af0bdfe7bb0ed55f9b761dff@gmail.com> References: <8735asoytw.fsf@laura> <87y1sknhb5.fsf@laura> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36858"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Nov 10 13:34:05 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 1ot6ku-0009NZ-Ln for guile-user@m.gmane-mx.org; Thu, 10 Nov 2022 13:34:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ot6jv-0007PC-OX; Thu, 10 Nov 2022 07:33:03 -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 1ot6jn-0007Op-0t for guile-user@gnu.org; Thu, 10 Nov 2022 07:32:58 -0500 Original-Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ot6jl-00083l-GR for guile-user@gnu.org; Thu, 10 Nov 2022 07:32:54 -0500 Original-Received: by mail-wr1-x42f.google.com with SMTP id v1so2019209wrt.11 for ; Thu, 10 Nov 2022 04:32:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:from:to:cc:subject:date:message-id :reply-to; bh=nQKp/hd34CvHQgJYU3TS1fMAxJuKxvW3K8/n0uU5y0U=; b=XYESv+m7qcZCSdQYpJ9zjSKqpNgsKxqpFO2j3dAQMf3OkO3VWAvWyLZ/Uy+m2yvHdu mz2aTa5QjjHzYFC8JEzRSTwCBuEX00AoC1lNwm/yj4dCZY6ocbD7Edx7jivtmkMp6jRj sxSGV+/UlRFWPFiD55e4df0sW+XExMD61r7aS5wCUhylxokWx6zMIFSzsQIOC95rHE4T VWfcruS+q0zdyOgGsY0TLM2/7N3A7OC3whF65jpnL0uYBvHVL/gOy+d4mE6TnEPm9mJH VzRRpi3rUd+C2Hpq7oYeCjN/pedFmM18d6Zz+fyVoPWkFwJmCUYhz4mvkMgCygM8iV9Q KZgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nQKp/hd34CvHQgJYU3TS1fMAxJuKxvW3K8/n0uU5y0U=; b=U3TlGg2OumP8bwY2uy4T8SIqfYaXHqkGBMbERWdAXUARSbRtLpB5q7bLXNovdcCMv8 oYOEAV24atOQvf6YFhls4klpCsDQKqRg3BwBfU+fxapVX9Z6gtRUdkgBJMf5ctYOjtk8 dnTVQ7BY6SqAZGoCN9vuBIIfL1VtalvTRfC6eHQHQQq+w/uTh+6g6yFuKzuHqwfjeClZ pUnCGCaQ4TQ+ur/zHAqO9/SJKxHUk1IGAZpTbuVMuA+Gvw4w17DOEK5UNZ4IaZJTMqoR 4n5OZECvaDfjoDBVaGb+LnUzvwcFK40FozTZhv7DWuBC6I+E5NQVf8XfYgstVWR6+Jdh Stag== X-Gm-Message-State: ACrzQf2xUZpmNoSXoFJ0OUnJFheLWxhnzH702heeiImPZcupy861QmwJ NlwgEDSqpe8bUEue/Gu1ZQUMe1PzO9Y= X-Google-Smtp-Source: AMsMyM4cfvrvD8wp2Eid4pdHinzSKoIIr3qW5nBbDyDdk9nRBjzaqPzaA8u4QuuQiLcyZJZoihuRXQ== X-Received: by 2002:a5d:6688:0:b0:238:3e06:9001 with SMTP id l8-20020a5d6688000000b002383e069001mr24727595wru.308.1668083571634; Thu, 10 Nov 2022 04:32:51 -0800 (PST) Original-Received: from dell.homenet (216.72.147.147.dyn.plus.net. [147.147.72.216]) by smtp.gmail.com with ESMTPSA id e10-20020a05600c4e4a00b003a3170a7af9sm5063977wmq.4.2022.11.10.04.32.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 04:32:51 -0800 (PST) Original-Received: from dell.homenet (localhost [127.0.0.1]) by dell.homenet (Postfix) with SMTP id 4B76F4227FE for ; Thu, 10 Nov 2022 12:32:45 +0000 (GMT) In-Reply-To: <87y1sknhb5.fsf@laura> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-unknown-linux-gnu) Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=vine.chris@gmail.com; helo=mail-wr1-x42f.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.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:18714 Archived-At: On Wed, 09 Nov 2022 12:55:42 -0500 Olivier Dion via General Guile related discussions wrote: > On Wed, 09 Nov 2022, Damien Mattei wrote: > > 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....) > > I'm not aware of any control mechanism that are implicit in Guile. You > almost always have to deal with a continuation object. However, nothing > prevent you to invent your own control flow wrapper. You can construct an anaphoric macro with that in mind. This introduces an imperative-style 'loop' macro which carries within the loop block a 'break' keyword which will cause the loop to exit: (use-modules (ice-9 control)) ;; for call/ec (define-syntax loop (lambda (x) (syntax-case x () [(k e ...) (with-syntax ([break (datum->syntax #'k 'break)]) #'(call/ec (lambda (break) (let f () e ... (f)))))]))) (display (let ([n 3] [lst '()]) (loop (if (= n 0) (break lst)) (set! lst (cons 'a lst)) (set! n (- n 1))))) (newline) However explicit control of loops is better in my view. Imperative loops usually end up with mutable bindings, as in the example above.