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: call/cc does not return a value Date: Fri, 13 Sep 2024 11:15:48 +0200 Message-ID: References: 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="13362"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: mikael@djurfeldt.com Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Sep 13 11:16:50 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 1sp2Q6-0003Lr-J2 for guile-user@m.gmane-mx.org; Fri, 13 Sep 2024 11:16:50 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp2PS-0003xd-G5; Fri, 13 Sep 2024 05:16:10 -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 1sp2PO-0003xC-RP for guile-user@gnu.org; Fri, 13 Sep 2024 05:16:07 -0400 Original-Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp2PK-0003Mw-Du for guile-user@gnu.org; Fri, 13 Sep 2024 05:16:06 -0400 Original-Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-6c352bcb569so10036386d6.0 for ; Fri, 13 Sep 2024 02:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726218961; x=1726823761; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IIJ5g8flLv1meS6z2TAYbeW3ltTYHIMjYAPIo8gVw20=; b=OnOdPNpj1NNbdhvbntdCAFMsF1frfHt9NaOLFMoZ9p4BduVjtk4oVjeHYVt12m2f51 2TWDfQfPktpC+q5yrt8lQMZfKzyU82KDPPmaAb6p4IrhCqcnX9+4rBOYuBJBs4JHTy8r p/vv8sGHQtFLRJumrLqCoysryBsQSqaA9oGG3lF9iBsEiKrwxB5w3kS9a12bBzQib1VZ scLWwZDuRe/Bhf1nW8y+djhA5iz9OrrjT2pBwDep3XV9aBoWUuP16+T/+hhx5pcc/baz RUb/hPv6jRoRRbMf3/5tq/yotyhi5HyMS/g+K2wIzipWuQO5UtUfAhpyTvS/AulES3NX /Z0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726218961; x=1726823761; h=cc: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=IIJ5g8flLv1meS6z2TAYbeW3ltTYHIMjYAPIo8gVw20=; b=kNuKYy5LdQVarRjcsJvBJz9nCTf6DOdFgyjDeLnE5Rual5mxjvD2/b30hhXEvILjgo tq9TJuGpu3kTByc74QCX4xUgg8qGIGwftgDYrfoXA/NwTR3Zn7ayPgJwGJMi/jDQ4GcO U3YQV2SFfwi9FclQN3oRgv/g1cDFlQ7tJSWKyX9VXI9JSTo/1Ihu82lUb6/VXOyxjo4i ZthRFPWrcM+oX1XWOIHuP94ir5S3eA/S/zxbe3gtAjKIdkmqPnGsbD0TkIS51v2YDcQm 9S1NeNESLf4ysTYNQvDg1KKGtAt9hugscYEvtOMWnqu6JcB/wAAufCqejYlsiGK3bEm6 6ORw== X-Gm-Message-State: AOJu0YyH+drs2iE5qf22vc1DngD2R914Yg19JBliXCiF1XLyb71TjSSo ipTy6DAszk4B0D5bh1oY1UoIkBq0r998ML7TIbUdOnzWk2+/+DZI07qUoiEVg4ebMzmAsBQ6ITT rYsmqn1fE2JSCpuF7nw7cshqe1WL2CmEG X-Google-Smtp-Source: AGHT+IHY2DMIMgrEnpIkTm8kZ24aZ9TRs16+jQTRK4l7bWtn8aZ8otQpJHTiKuxvfXT1yS60RsNE0nfZ913U1kEsQdE= X-Received: by 2002:a05:6214:3d9b:b0:6c5:5088:94e0 with SMTP id 6a1803df08f44-6c57355acdcmr78435136d6.15.1726218961057; Fri, 13 Sep 2024 02:16:01 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::f35; envelope-from=damien.mattei@gmail.com; helo=mail-qv1-xf35.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:19801 Archived-At: hello Mikael, you remark help because ,even if 'let' and 'let-syntax' seems interchangeable here, there was indeed a problem with syntax.... i did not write myself the macro originally and when comparing with def.scm 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 should be simply stx and not (syntax kwd) or (syntax stx) in the macro definition, 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 bindi= ng > > `if' > > WARNING: (Scheme+): imported module (when-unless) overrides core bindin= g > > `when' > > WARNING: (Scheme+): imported module (when-unless) overrides core bindin= g > > `unless' > > > > 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 > > > > here i should get "finish" at REPL but nothing happens? > > > > regards >