* call/cc does not return a value
@ 2024-09-13 6:52 Damien Mattei
2024-09-13 8:25 ` Mikael Djurfeldt
0 siblings, 1 reply; 5+ messages in thread
From: Damien Mattei @ 2024-09-13 6:52 UTC (permalink / raw)
To: guile-user
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 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 (= i 2) (break "finish")))
0
1
2
here i should get "finish" at REPL but nothing happens?
regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: call/cc does not return a value
2024-09-13 6:52 call/cc does not return a value Damien Mattei
@ 2024-09-13 8:25 ` Mikael Djurfeldt
2024-09-13 9:15 ` Damien Mattei
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Djurfeldt @ 2024-09-13 8:25 UTC (permalink / raw)
To: Damien Mattei; +Cc: guile-user, Mikael Djurfeldt
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 AM Damien Mattei <damien.mattei@gmail.com> 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 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 (= i 2) (break "finish")))
> 0
> 1
> 2
>
> here i should get "finish" at REPL but nothing happens?
>
> regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: call/cc does not return a value
2024-09-13 8:25 ` Mikael Djurfeldt
@ 2024-09-13 9:15 ` Damien Mattei
2024-09-13 9:29 ` Mikael Djurfeldt
0 siblings, 1 reply; 5+ messages in thread
From: Damien Mattei @ 2024-09-13 9:15 UTC (permalink / raw)
To: mikael; +Cc: guile-user
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 (= i 2) (break "finish")))
0
1
2
$1 = "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 AM Mikael Djurfeldt <mikael@djurfeldt.com>
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 AM Damien Mattei <damien.mattei@gmail.com>
> 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 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 (= i 2) (break "finish")))
> > 0
> > 1
> > 2
> >
> > here i should get "finish" at REPL but nothing happens?
> >
> > regards
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: call/cc does not return a value
2024-09-13 9:15 ` Damien Mattei
@ 2024-09-13 9:29 ` Mikael Djurfeldt
2024-09-13 10:52 ` Damien Mattei
0 siblings, 1 reply; 5+ messages in thread
From: Mikael Djurfeldt @ 2024-09-13 9:29 UTC (permalink / raw)
To: Damien Mattei; +Cc: guile-user
(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 AM Damien Mattei <damien.mattei@gmail.com> 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 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 (= i 2) (break "finish")))
> 0
> 1
> 2
> $1 = "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 AM Mikael Djurfeldt <mikael@djurfeldt.com> 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 AM Damien Mattei <damien.mattei@gmail.com> 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 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 (= i 2) (break "finish")))
>> > 0
>> > 1
>> > 2
>> >
>> > here i should get "finish" at REPL but nothing happens?
>> >
>> > regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: call/cc does not return a value
2024-09-13 9:29 ` Mikael Djurfeldt
@ 2024-09-13 10:52 ` Damien Mattei
0 siblings, 0 replies; 5+ messages in thread
From: Damien Mattei @ 2024-09-13 10:52 UTC (permalink / raw)
To: mikael; +Cc: guile-user
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 =
(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 (= 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 (= i 2) (break i))))
res)
#<eof>
> (foo)
(foo)
0
1
2
2
#<eof>
>
On Fri, Sep 13, 2024 at 11:30 AM Mikael Djurfeldt <mikael@djurfeldt.com>
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 AM Damien Mattei <damien.mattei@gmail.com>
> 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 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 (= i 2) (break "finish")))
> > 0
> > 1
> > 2
> > $1 = "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 AM Mikael Djurfeldt <mikael@djurfeldt.com>
> 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 AM Damien Mattei <damien.mattei@gmail.com>
> 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
> 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 (= i 2) (break "finish")))
> >> > 0
> >> > 1
> >> > 2
> >> >
> >> > here i should get "finish" at REPL but nothing happens?
> >> >
> >> > regards
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-09-13 10:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-13 6:52 call/cc does not return a value Damien Mattei
2024-09-13 8:25 ` Mikael Djurfeldt
2024-09-13 9:15 ` Damien Mattei
2024-09-13 9:29 ` Mikael Djurfeldt
2024-09-13 10:52 ` Damien Mattei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).