Multiple returns from vector-map

2 views
Skip to first unread message

Eduardo Cavazos

unread,
Jul 6, 2011, 8:57:22 PM7/6/11
to Mosh Developer Disscus
Hello,

Section 11.3 of R6RS says:

"If multiple returns occur from vector-map, the return values returned
by earlier returns are not mutated."

Consider this bit of code:

(define v0 (vector 1 2 3 4 5 6))

(define cl '()) ; Where we'll save the continuations

(define v1

(vector-map (lambda (elt)

(call/cc

(lambda (c)

(set! cl (cons c cl))

(* elt elt))))

v0))

(define v2 v1)

((list-ref (reverse cl) 0) 'x)

(list v0 v1 v2)

In the resulting list, the values for v1 and v2 should be different.
I.e. calling the continuation should not affect the value stored in
v2. But in Mosh (0.2.6), the value in v2 is changed. This seems to go
against section 11.3. Chez and Ypsilon seem to follow the spec.

Ed

Marco Maggi

unread,
Jul 7, 2011, 1:24:16 AM7/7/11
to mosh-develo...@googlegroups.com
Eduardo Cavazos wrote:

> (define v0 (vector 1 2 3 4 5 6))
> (define cl '()) ; Where we'll save the continuations
> (define v1
> (vector-map (lambda (elt)
> (call/cc
> (lambda (c)
> (set! cl (cons c cl))
> (* elt elt))))
> v0))
> (define v2 v1)
> ((list-ref (reverse cl) 0) 'x)
> (list v0 v1 v2)

This goes into infinite loop? I modified it as:

#!r6rs
(import (rnrs))

(define only-once #t)


(define v0 (vector 1 2 3 4 5 6))
(define cl '())

(define v1
(vector-map (lambda (elt)
(call/cc
(lambda (c)
(set! cl (cons c cl))
(* elt elt))))
v0))

(define v2 v1)
(write v0)(newline)
(write v1)(newline)
(write v2)(newline)
(when only-once
(set! only-once #f)
((car (reverse cl)) 'x))

and I get:

~/var/tmp $ mosh-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(x 4 9 16 25 36)
#(x 4 9 16 25 36)
~/var/tmp $ petite-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(1 4 9 16 25 x)
#(1 4 9 16 25 x)
~/var/tmp $ ypsilon-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(x 4 9 16 25 36)
#(x 4 9 16 25 36)
~/var/tmp $ larceny-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(x 4 9 16 25 36)
#(x 4 9 16 25 36)
~/var/tmp $ vicare-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(x 4 9 16 25 36)
#(x 4 9 16 25 36)
~/var/tmp $ plt-r6rs proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
define-values: cannot re-define a constant: v1 in module: "/home/marco/var/tmp/proof.sps"
~/var/tmp $ guile proof.sps
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/marco/var/tmp/proof.sps
;;; compiled /home/marco/.cache/guile/ccache/2.0-LE-4-2.0/home/marco/var/tmp/proof.sps.go
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)
#(1 4 9 16 25 36)
#(1 2 3 4 5 6)
#(x 4 9 16 25 36)
#(x 4 9 16 25 36)

I see X's everywhere.
--
Marco Maggi

Marco Maggi

unread,
Jul 7, 2011, 1:35:27 AM7/7/11
to mosh-develo...@googlegroups.com
Eduardo Cavazos wrote:
> "If multiple returns occur from vector-map, the return
> values returned by earlier returns are not mutated."

Sorry, ignore the script in my other message. It should be
the following:

#!r6rs
(import (rnrs))

(let ((only-once #t)
(v0 (vector 1 2 3 4 5 6))
(cl '())
(old-v1 #f))
(let ((v1 (vector-map (lambda (elt)


(call/cc
(lambda (c)
(set! cl (cons c cl))
(* elt elt))))

v0)))


(when only-once
(set! only-once #f)

(set! old-v1 v1)
((car (reverse cl)) 'x))

(write v0)(newline)
(write old-v1)(newline)
(write v1)(newline)))

which yields the following results:

~/var/tmp $ petite-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)

#(1 4 9 16 25 x)


~/var/tmp $ vicare-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)

#(x 4 9 16 25 36)

~/var/tmp $ ypsilon-script proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)

#(x 4 9 16 25 36)
~/var/tmp $ plt-r6rs proof.sps
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)

#(x 4 9 16 25 36)

~/var/tmp $ guile proof.sps
;;; note: source file /home/marco/var/tmp/proof.sps
;;; newer than compiled /home/marco/.cache/guile/ccache/2.0-LE-4-2.0/home/marco/var/tmp/proof.sps.go


;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/marco/var/tmp/proof.sps
;;; compiled /home/marco/.cache/guile/ccache/2.0-LE-4-2.0/home/marco/var/tmp/proof.sps.go
#(1 2 3 4 5 6)
#(1 4 9 16 25 36)

#(x 4 9 16 25 36)

~/var/tmp $ mosh-script proof.sps
#(1 2 3 4 5 6)

#(x 4 9 16 25 36)
#(x 4 9 16 25 36)

so, yes Mosh is the only failing one.
--
Marco Maggi

higepon

unread,
Jul 7, 2011, 3:34:23 AM7/7/11
to mosh-develo...@googlegroups.com
Hi.

Thanks Ed.
I didn't realize this.
Fixed and added test.

https://github.com/higepon/mosh/commit/80664a98bd1cf9e699b691f92d270ebaa9b9e83b

Thanks Marco Maggi, I've added your test too.

Cheers.

---  --
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/
http://twitter.com/higepon

> --
> You received this message because you are subscribed to the Google Groups "Mosh Developer Disscus" group.
> To post to this group, send email to mosh-develo...@googlegroups.com.
> To unsubscribe from this group, send email to mosh-developer-di...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mosh-developer-discuss?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages