From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.user Subject: Re: call/cc does not return a value Date: Fri, 13 Sep 2024 11:29:58 +0200 Message-ID: References: Reply-To: mikael@djurfeldt.com Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31681"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Damien Mattei Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Sep 13 11:30:39 2024 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 1sp2dT-00085J-Or for guile-user@m.gmane-mx.org; Fri, 13 Sep 2024 11:30:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp2d3-0002UL-Sp; Fri, 13 Sep 2024 05:30:13 -0400 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 1sp2d1-0002UB-W9 for guile-user@gnu.org; Fri, 13 Sep 2024 05:30:12 -0400 Original-Received: from mail-vk1-f172.google.com ([209.85.221.172]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp2d0-0004fj-BY for guile-user@gnu.org; Fri, 13 Sep 2024 05:30:11 -0400 Original-Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-501269674daso179542e0c.0 for ; Fri, 13 Sep 2024 02:30:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726219809; x=1726824609; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qabGFA1OzudrHAyDEdxoHb8W0vc4Ks0MoSkekFXgAd4=; b=NEqq9CtDPwETZZsxXlBNe/IUOvJE2r/CmWMNVGAIAPgBBtnsh0rxQV21/AZzTAZti3 /mchp1gxba+5jTpoZF8M03cZBQfwRF8wPx3qeMDdmD1RZ45l519D78HnIXX3yYo3zhMo TClVWbI/5audSWsHolYK19J0ecsOZhEYJgjU8NYheQeQ5xpBz0aJmmIndQd6uuwyd0th VEAAw7Xq2j2YxdvxWexxyyTvH9xLIoU5EZoQMNUAQr3cOEpXlqA1LvbSp4YvMneaRCtX F5ECV8PmJS4LqGESFIu39BQC/WYx6rwO/uz9JNSyEHZRFgbj7DxqY+Zmo/kwD9M7sGru QHWw== X-Gm-Message-State: AOJu0YyqzmFLEsFVmQ5obq788IdeyHmv1RuccpeCFcLkDM9WCGnxaDSO E9+eL7KBd3i4q7CRqW7VGqASkOMo3DRGtOAKXpfdopfOyouCVI9JKMlc8MUV58lBEGlmfTxiLyv BSegEw9PohS9GJrR8N3rbxPRVQ74= X-Google-Smtp-Source: AGHT+IFthRM1luiO825zvy6+aCZ2370PFboqbx/qQACyv8K5yah0QMBWZhE4MvR5w/It1DqDedTCk7qDrT9y4XzpIAo= X-Received: by 2002:a05:6122:3b12:b0:4ef:6870:ff5 with SMTP id 71dfb90a1353d-50344b7fffcmr1079435e0c.5.1726219809125; Fri, 13 Sep 2024 02:30:09 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=209.85.221.172; envelope-from=mdjurfeldt@gmail.com; helo=mail-vk1-f172.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:19802 Archived-At: (Well, I thought the main reason why it didn't return a value was (escape) in the old code, i.e., the continuation is called without arguments.) On Fri, Sep 13, 2024 at 11:16=E2=80=AFAM Damien Mattei wrote: > > hello Mikael, > > you remark help because ,even if 'let' and 'let-syntax' seems interchange= able here, there was indeed a problem with syntax.... > i did not write myself the macro originally and when comparing with def.s= cm that allow returning value from a function there was a difference, there= was no use of kwd and stx should be used in place of it and even more it s= hould be simply stx and not (syntax kwd) or (syntax stx) in the macro defin= ition, here is the final version of code: > > > (define-syntax for > > (lambda (stx) > > (syntax-case stx () > > ((_ (init test incrmt) body ...) > > (with-syntax ((BREAK (datum->syntax stx 'break)) > (CONTINUE (datum->syntax stx 'continue))) > (syntax > (call/cc > (lambda (escape) > (let ((BREAK escape)) > init > (let loop () > (when test > (call/cc > (lambda (next) > (let ((CONTINUE next)) > (let () ;; allow definitions > body ...)))) ; end call/cc > incrmt > (loop))) ; end let loop > ))))) ;; close with-syntax > )))) > > and the good result now with Guile and Racket (not yet modified Kawa): > > scheme@(guile-user)> (for ((define i 0) (< i 5) (set! i (+ i 1))) (define= x 7) (display i) (newline) (when (=3D i 2) (break "finish"))) > 0 > 1 > 2 > $1 =3D "finish" > > thank for you help , without you i would not have look so closely to this= macro written many years ago and used in the Guile,Racket and Kawa version= of Scheme+... > > Damien > > On Fri, Sep 13, 2024 at 10:25=E2=80=AFAM Mikael Djurfeldt wrote: >> >> Hi Damien, >> >> Maybe I'm missing something, but shoudn't it be: >> >> (define-syntax for >> (lambda (stx) >> (syntax-case stx () >> ((kwd (init test incrmt) body ...) >> (with-syntax ((BREAK (datum->syntax (syntax kwd) 'break)) >> (CONTINUE (datum->syntax (syntax kwd) 'continue))) >> (syntax >> (call/cc >> (lambda (escape) >> (let ((BREAK escape)) >> init >> (let loop () >> (when test >> (call/cc >> (lambda (next) >> (let ((CONTINUE next)) >> (let () ;; allow definitions >> body ...)))) ; end call/cc >> incrmt >> (loop))) ; end let loop >> ))))) ;; close with-syntax >> )))) >> >> ? >> >> On Fri, Sep 13, 2024 at 8:53=E2=80=AFAM Damien Mattei wrote: >> > >> > hello, >> > >> > i believed call/cc allowed to return value but i have this macro and i= can >> > use continuation, but the value is not passed to the continuation: >> > >> > (define-syntax for >> > (lambda (stx) >> > (syntax-case stx () >> > ((kwd (init test incrmt) body ...) >> > >> > (with-syntax ((BREAK (datum->syntax (syntax kwd) 'break)) >> > (CONTINUE (datum->syntax (syntax kwd) 'continue)= )) >> > >> > (syntax >> > (call/cc >> > (lambda (escape) >> > (let-syntax ((BREAK (identifier-syntax (escape)))) >> > init >> > (let loop () >> > (when test >> > (call/cc >> > (lambda (next) >> > (let-syntax ((CONTINUE (identifier-syntax (next)))) >> > (let () ;; allow definitions >> > body ...)))) ; end call/cc >> > incrmt >> > (loop))) ; end let loop >> > ))))) ;; close with-syntax >> > )))) >> > >> > >> > mattei@acer:~$ guile >> > GNU Guile 3.0.9 >> > Copyright (C) 1995-2023 Free Software Foundation, Inc. >> > >> > Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. >> > This program is free software, and you are welcome to redistribute it >> > under certain conditions; type `,show c' for details. >> > >> > Enter `,help' for help. >> > scheme@(guile-user)> (use-modules (Scheme+)) >> > WARNING: (Scheme+): imported module (if-then-else) overrides core bind= ing >> > `if' >> > WARNING: (Scheme+): imported module (when-unless) overrides core bindi= ng >> > `when' >> > WARNING: (Scheme+): imported module (when-unless) overrides core bindi= ng >> > `unless' >> > >> > scheme@(guile-user)> (for ((define i 0) (< i 5) (set! i (+ i 1))) (def= ine x >> > 7) (display i) (newline) (when (=3D i 2) (break "finish"))) >> > 0 >> > 1 >> > 2 >> > >> > here i should get "finish" at REPL but nothing happens? >> > >> > regards