From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: Re: escaping from a recursive call Date: Wed, 09 Nov 2022 12:55:42 -0500 Message-ID: <87y1sknhb5.fsf@laura> References: <8735asoytw.fsf@laura> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29859"; mail-complaints-to="usenet@ciao.gmane.io" To: Damien Mattei , guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Nov 09 18:56:54 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 1ospJl-0007ZE-Ie for guile-user@m.gmane-mx.org; Wed, 09 Nov 2022 18:56:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ospIr-0001Xn-3A; Wed, 09 Nov 2022 12:55:57 -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 1ospIo-0001XA-15 for guile-user@gnu.org; Wed, 09 Nov 2022 12:55:54 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ospIk-0007bp-QK for guile-user@gnu.org; Wed, 09 Nov 2022 12:55:52 -0500 Original-Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2A9HtgrR010519; Wed, 9 Nov 2022 12:55:46 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2A9HtgrR010519 In-Reply-To: X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Wed, 9 Nov 2022 17:55:42 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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:18703 Archived-At: 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. For example: --8<---------------cut here---------------start------------->8--- (define my-prompt (make-prompt-tag)) (define-syntax-rule (return-now x) (abort-to-prompt my-prompt x)) (define (wrap-this procedure) (let ((inside? #f)) (lambda args (if inside? (apply procedure args) (begin (set! inside? #t) (let ((ret (call-with-prompt my-prompt (lambda () (apply procedure args)) (lambda (_ x) x)))) (set! inside? #f) ret)))))) (define-syntax define-interruptible (syntax-rules () ((_ (name formals ...) body ...) (define name (wrap-this (lambda (formals ...) body ...)))))) (define-interruptible (foo n) (cond ((= n 0) 'end0) ((= n 7) (return-now 'end7)) (else (cons n (foo (1- n)))))) (pk (foo 5)) (pk (foo 10)) --8<---------------cut here---------------end--------------->8--- There's probably other way of doing so that I'm not aware of. -- Olivier Dion oldiob.dev