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 12:52:00 +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="7928"; 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 12:53:07 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 1sp3vH-0001sj-Lo for guile-user@m.gmane-mx.org; Fri, 13 Sep 2024 12:53:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp3uU-0000uT-FV; Fri, 13 Sep 2024 06:52:18 -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 1sp3uT-0000uJ-N5 for guile-user@gnu.org; Fri, 13 Sep 2024 06:52:17 -0400 Original-Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp3uQ-0006JS-UT for guile-user@gnu.org; Fri, 13 Sep 2024 06:52:16 -0400 Original-Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-7a9a30a045cso187278185a.2 for ; Fri, 13 Sep 2024 03:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726224733; x=1726829533; 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=RHUIyeM6E3ZaMKEY37CAzX8pEhvBGn571RmHN16Hrro=; b=HBJNaZkndUNVCL/5BoZs2q3EQCRMTe1/MEv8p4ylmk65erbVlyuAhw4pLw+mXJk5Q6 gYFTWfmVgozSqVueM+wb0UXmver8OICuVO1Uup8rgETwwnOzGPjm3KVDpD2RrVvfQLkk ISC0ZcVQeIj6G6wEYLCkmn4DTZE1FomcfNWYoCZ3UdT1iAdAQZ9cbFW8ceCAD6eIO/L2 ONih4YrVyZTPDDsfwPEmtr36D/KgUpSBNXlu5o8l9cCKMOJNkYapNgw2HwTX1WHyomp/ qcj2082SqkzlZrKatXFdWvCzwST9fHLrh8yvJB8Cv76hmU8YC1ivxelMZUBFbggZWIcv 0cag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726224733; x=1726829533; 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=RHUIyeM6E3ZaMKEY37CAzX8pEhvBGn571RmHN16Hrro=; b=N7652qnkzWAUL2c9L43NkxvaG4oCTd3NmiUbuPV7SKhKWH3VFUyKTtDmAMFEqX9XH5 NUXtomyOyeJVpg2cDLF5zpj24zdJhuhH1IdhZnEXvTo1rvYAS1IPZpt5vqwQIWrgsscx c7vBw9xq2tc6HTgO5UmGg9WcpTYkQC/zRO9rKX+hs/atSUfJ/A85EK3UGelX16D3PNag xQFF7gOeOV/JMdckxJYewOUx60JFZUnoddvkvx3pbKeQj5vSaIIGMh212cYdX1B6ItlB lc0OPcf+tPe7ibhUAkbyaLosZXewK/GPQC5Ti2ilsIzLEnWarpY28ltSgFMTJNbbQdxV MRIg== X-Gm-Message-State: AOJu0YwKWvoDD7uLyxZe1G1tSeW4As0ChKybyQVKBikVp6YeN0aByyoS UDEDGk2f+i/MqeVact5Ft1LyY1n4l50NriH8lM7lVRaCYBW+dmEY8ImuCSeOMM2ibQUneDdT5K0 cXIca7TEXEl6t3J4qwQoixWcpJDe7OOLt X-Google-Smtp-Source: AGHT+IEyVyauQEwTHns/Of8a84zrtlGyFzwCdYgB7kY9Vs8d7yi0HGl6vM/DpFb9+2/U4teuWNO///IAGqOQPUUWlu8= X-Received: by 2002:a05:620a:2952:b0:7a9:acd0:c8c4 with SMTP id af79cd13be357-7a9e5fb552amr875596685a.52.1726224733223; Fri, 13 Sep 2024 03:52:13 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=damien.mattei@gmail.com; helo=mail-qk1-x72a.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:19803 Archived-At: well... when i test it in R6RS only your solution works, let and let-syntax are no more interchangeable and all the stuff with kwd and syntax must be keep :-O at least in Racket/R6RS , not tested in Guile/R6RS: (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 )))) and the REPL window: Welcome to DrRacket, version 8.14 [cs]. Language: reader SRFI-105, with debugging; memory limit: 8192 MB. SRFI-105 Curly Infix parser for Racket Scheme by Damien MATTEI (based on code from David A. Wheeler and Alan Manuel K. Gloria.) Possibly skipping some header's lines containing space,tabs,new line,etc or comments. Detected R6RS code: #!r6rs SRFI-105.rkt : number of skipped lines (comments, spaces, directives,...) at header's beginning : 7 Parsed curly infix code result =3D (module aschemeplusr6rsprogram r6rs (library (r6rs-srfi-105-repl) (export) (import (except (rnrs base (6)) if) (only (srfi :43) vector-append) (rnrs syntax-case (6)) (only (racket) print-mpair-curly-braces) (only (rnrs control (6)) when) (only (rnrs io simple (6)) display newline) (Scheme+R6RS)) (print-mpair-curly-braces #f)) ) > (define (foo) (define res (for ((define i 0) (< i 5) (set! i (+ i 1))) (define x 7) (display i) (newline) (when (=3D i 2) (break i)))) res) (define (foo) (define res (for ((define i 0) (< i 5) (set! i (+ i 1))) (define x 7) (display i) (newline) (when (=3D i 2) (break i)))) res) # > (foo) (foo) 0 1 2 2 # > On Fri, Sep 13, 2024 at 11:30=E2=80=AFAM Mikael Djurfeldt wrote: > (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 > 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 mo= re > 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 i= t > >> > 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 > binding > >> > `if' > >> > WARNING: (Scheme+): imported module (when-unless) overrides core > binding > >> > `when' > >> > WARNING: (Scheme+): imported module (when-unless) overrides core > binding > >> > `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 >