Hello,
I have a file "test.scm" containing the following lines:
(import (std srfi/1))
(define a '(3 2 4 2)) (append! a '(8 8 8))
(display a) (newline)
When I lauch: gsc -e '(load "~~/lib/modules/build")' - and then (import test) it displays '(3 2 4 2 8 8 8)', which is fine. But if 'test' has been compiled first with (module-compile! 'test), then when importing I got the error:
*** ERROR IN ##main -- (Argument 1) MUTABLE object expected (set-cdr! '(2) '(8 8 8))
(I use the last git version of BH)
Afficher les réponses par date
This is not a problem with blackhole. Your program contains an error because it is trying to mutate a constant. In Scheme, quoted objects are not mutable and it is an error to mutate them. The interpreter does not enforce this error because it implements constants using mutable objects. The compiler implements constants using "permanent objects" which cannot be mutated (they are not scanned by the garbage collector).
You could fix your program by doing
(define a (list 3 2 4 2))
instead of
(define a '(3 2 4 2))
Marc
On 2010-08-06, at 9:26 AM, Yves Parès wrote:
Hello,
I have a file "test.scm" containing the following lines:
(import (std srfi/1))
(define a '(3 2 4 2)) (append! a '(8 8 8))
(display a) (newline)
When I lauch: gsc -e '(load "~~/lib/modules/build")' - and then (import test) it displays '(3 2 4 2 8 8 8)', which is fine. But if 'test' has been compiled first with (module-compile! 'test), then when importing I got the error:
*** ERROR IN ##main -- (Argument 1) MUTABLE object expected (set-cdr! '(2) '(8 8 8))
(I use the last git version of BH) _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Okay, thanks. I didn't knew that.
Speaking about BlackHole, I was wondering: how could one define his own module resolver? For instance I saw that termite has a BH version. But I don't know how I could import it if I install it system-wide.
2010/8/6 Marc Feeley feeley@iro.umontreal.ca
This is not a problem with blackhole. Your program contains an error because it is trying to mutate a constant. In Scheme, quoted objects are not mutable and it is an error to mutate them. The interpreter does not enforce this error because it implements constants using mutable objects. The compiler implements constants using "permanent objects" which cannot be mutated (they are not scanned by the garbage collector).
You could fix your program by doing
(define a (list 3 2 4 2))
instead of
(define a '(3 2 4 2))
Marc
On 2010-08-06, at 9:26 AM, Yves Parès wrote:
Hello,
I have a file "test.scm" containing the following lines:
(import (std srfi/1))
(define a '(3 2 4 2)) (append! a '(8 8 8))
(display a) (newline)
When I lauch: gsc -e '(load "~~/lib/modules/build")' - and then (import test) it displays '(3 2 4 2 8 8 8)', which is fine. But if 'test' has been compiled first with (module-compile! 'test), then
when importing I got the error:
*** ERROR IN ##main -- (Argument 1) MUTABLE object expected (set-cdr! '(2) '(8 8 8))
(I use the last git version of BH) _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Still with append!, I have another problem. If my list is initially empty, append! does not alter it:
(define a (list)) (append! a (list 1 2 3))
And a remains empty... I don't know if it is normal
2010/8/6 Yves Parès limestrael@gmail.com
Okay, thanks. I didn't knew that.
Speaking about BlackHole, I was wondering: how could one define his own module resolver? For instance I saw that termite has a BH version. But I don't know how I could import it if I install it system-wide.
2010/8/6 Marc Feeley feeley@iro.umontreal.ca
This is not a problem with blackhole. Your program contains an error
because it is trying to mutate a constant. In Scheme, quoted objects are not mutable and it is an error to mutate them. The interpreter does not enforce this error because it implements constants using mutable objects. The compiler implements constants using "permanent objects" which cannot be mutated (they are not scanned by the garbage collector).
You could fix your program by doing
(define a (list 3 2 4 2))
instead of
(define a '(3 2 4 2))
Marc
On 2010-08-06, at 9:26 AM, Yves Parès wrote:
Hello,
I have a file "test.scm" containing the following lines:
(import (std srfi/1))
(define a '(3 2 4 2)) (append! a '(8 8 8))
(display a) (newline)
When I lauch: gsc -e '(load "~~/lib/modules/build")' - and then (import test) it displays '(3 2 4 2 8 8 8)', which is fine. But if 'test' has been compiled first with (module-compile! 'test), then
when importing I got the error:
*** ERROR IN ##main -- (Argument 1) MUTABLE object expected (set-cdr! '(2) '(8 8 8))
(I use the last git version of BH) _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
2010/8/6 Yves Parès limestrael@gmail.com:
Still with append!, I have another problem. If my list is initially empty, append! does not alter it:
(define a (list)) (append! a (list 1 2 3))
And a remains empty... I don't know if it is normal
|append!| doesn't mutate the binding for |a|, it mutates the list which is stored at |a| and returns the mutated list.
Unlike a vector, a list is not an object all by itself, instead it is a term used to describe chains of pair objects pairing some other object and the rest of the list, with the null object as the end marker, thus the null object all by itself to represent the empty list case. A pair object can be mutated, which is what (append! (list 'a 'b) (list 1 2 3)) does for the pair containing 'b, but a null object cannot be made to contain anything. So (append! (list) (list 1 2 3)) just returns its second argument. Since you don't mutate the |a| binding, you're not seeing any effect (since there has in fact been none).
What you seem to want to do is:
(set! a (append! a (list 1 2 3)))
Or maybe you want an object containing a (possibly empty) list that can be extended through mutation, in which case you could use a box containing the list:
(define a (box (list))) (define (boxedlist-append! boxedlist list) (set-box! boxedlist (append! (unbox boxedlist) list))) (boxedlist-append! a (list 1 2 3))
But you don't see that done often, because the spirit of Scheme is using functional updates, i.e. passing the extended list to the next function call, so no mutation is necessary.
Christian.