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: escaping from a recursive call Date: Wed, 9 Nov 2022 16:56:39 +0100 Message-ID: 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="11904"; 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 16:57:39 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 1osnSN-0002v4-Hk for guile-user@m.gmane-mx.org; Wed, 09 Nov 2022 16:57:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osnRf-0001Uy-UQ; Wed, 09 Nov 2022 10:56: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 1osnRd-0001TW-TN for guile-user@gnu.org; Wed, 09 Nov 2022 10:56:53 -0500 Original-Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1osnRc-00052C-6L for guile-user@gnu.org; Wed, 09 Nov 2022 10:56:53 -0500 Original-Received: by mail-ej1-x62d.google.com with SMTP id t25so47842877ejb.8 for ; Wed, 09 Nov 2022 07:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=93CtoFM1ejmMGALaPeSmfHAks65izxlXuPJo6yhGgiY=; b=EiVT8lctxBsW4Ss0JZWSjc/hYfTz+bCzWNsQZ+fMQUdNCRxKe4ezkJpvNeV76IP1s8 a+dzpXXpA6+fj0nQuTV51Ve4525GUhpgYAxWxtgimaC6m1G3KtVafe5cWd5IIyTRm3a+ KfOiSHm2CnxOR5aLIB6uiOEajm33XYDjI5Qz2y1EA0zSWyf11bHIW+g8TuXd4RxjqqOM 6EfmwDG69DwdhCskJt7PgVmnQhzyxfnmIWgPojI3CYO8vlYpy1fvgSDqtePzpsiY2Ntn Nvd2rG5kM5Vn7JuPuHddI07WufIsw2UOV+JMl6GiXrjTy2YgdwZwjD0EyzMITL2HtGjA 0k3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=93CtoFM1ejmMGALaPeSmfHAks65izxlXuPJo6yhGgiY=; b=MKpqNruhW3cE+8Qw1rc+Fnj1J479OF9flV+zp634MfDEHVQRtAL74tja5ZE9rP4DTL F4Uy/u53AZJTwWEdhuuxSWxmWF6aU0tP+Fu70KUKh+QZiw+DsbvG7zptSPsU1L0On6K6 5BfIqyHfR+yBhAnwLdoBd/K0lYhv8kR7laf24tE3h91PZB1CSeuliU4w0LzuhbZs24re VS4sDfbNaTm3voTIajzQOu5ykbQbtexPr7kX1eCQt7BFfUNUlgY/Od1kQH7fASldC7m+ Qj8LVq9zPn1i+f0bSRdvqCclCnJFJqrQ6198WUdOEF4TML2Zrujxl8UUvSl8Y4+ixrBF er2A== X-Gm-Message-State: ACrzQf2E4CRKMViSiO1ekBiGfIh08/1QUjTAFBv2I48huuEEfJG+Iq6b aLv6i7EZcqBNjOhslgdlfgsNuvqjVhpZdcx4Bxj1s+0LAEs= X-Google-Smtp-Source: AMsMyM6ejiI5+Q2Le0YQ8BaIftgxj6P4y9WjmWY2PXPGW39hsLU0rEvGXhzhEQCfnm5fIYGHWOxwzkZCNlTFv55dFtw= X-Received: by 2002:a17:907:783:b0:76e:f290:8b5 with SMTP id xd3-20020a170907078300b0076ef29008b5mr58569982ejb.395.1668009410431; Wed, 09 Nov 2022 07:56:50 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x62d.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:18700 Archived-At: 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}))))) cheme@(guile-user)> (foo 5) (5 4 3 2 1 . end0) scheme@(guile-user)> (foo 10) (10 9 8 . end7) it has just escaped from the current call to foo (def (bar n) (cond ((= n 0) 'end0) ((= n 7) (return-rec 'end7)) (else (cons n (bar {n - 1}))))) scheme@(guile-user)> (bar 5) (5 4 3 2 1 . end0) scheme@(guile-user)> (bar 10) ice-9/boot-9.scm:1669:16: In procedure raise-exception: Unbound variable: return-rec i admit i should read the K. Dybvig macro paper but still had not completely do it. i modify this code of my Scheme+ but it fails on (bar 10) : (define-syntax def (lambda (stx) (syntax-case stx () ;; multiple definitions without values assigned ;; (def (x y z)) ((_ (var1 ...)) #`(begin (define var1 '()) ...)) ;; (def (foo) (when #t (return "hello") "bye")) ;; ((_ ( ...) * ...) ;; (let ((ret-id (datum->syntax stx 'return))) ;; #`(define ( ...) ;; (call/cc (lambda (#,ret-id) * ...))))) ((_ ( ...) * ...) (let ((ret-id (datum->syntax stx 'return)) (ret-rec-id (datum->syntax stx 'return-rec))) #`(define ( ...) (define ( ...) (call/cc (lambda (#,ret-id) * ...))) (call/cc (lambda (#,ret-rec-id) ( ...)))))) ;; single definition without a value assigned ;; (def x) ((_ var) #`(define var '())) ;; (def x 7) ((_ var expr) #`(define var expr)) ((_ err ...) #`(syntax-error "Bad def form")) ))) i'am even surprised it works on (bar 5) if someone had a solution to this problem i will again copy/paste it in my code and gracefully thanks him a lot :-) best regards, damien