Re: things are eq? but not generated at the same time
On Wed, Sep 05, 2012 at 08:24:58PM +0100, Ian Price wrote: I, of course, meant vector literals, but a quick test shows this is not the case. Literals are always immutable, and trying to modify them is nasal demon stuff. Of course, R6RS says implementations should raise an exception when an attempt is made to modify an immutable object, so perhaps that is something we should consider. Related: http://stackoverflow.com/a/12332939/13 Cheers, Chris.
things are eq? but not generated at the same time
Hi, I found that this optimization can lead to dangerous bugs. If I put, (define a #(1)) (define b #(1)) , load the file. Then (eq? a b) #t Is this an optimization we need. I can figure out applications where you do not want this behavior e.g. I wan't to make distinct objects and add metadata by making a vector of it. Now different objects might have the same metadata and now go against my intuition and coerce the objects. I fear that many difficult to spot bugs will come out of this design choice! /Stefan
Re: things are eq? but not generated at the same time
Stefan Israelsson Tampe stefan.ita...@gmail.com writes: Is this an optimization we need. I can figure out applications where you do not want this behavior e.g. I wan't to make distinct objects and add metadata by making a vector of it. Now different objects might have the same metadata and now go against my intuition and coerce the objects. I'm not sure I understand what you are trying to say, make vector of what, the distinct objects? Then you can't do that as a vector literal anyway. Anyway if vectors are immutable, as I believe they are, it doesn't really harm to make them eq? If you want distinctness and mutability, you can always call the vector constructor. -- Ian Price -- shift-reset.com Programming is like pinball. The reward for doing it well is the opportunity to do it again - from The Wizardy Compiled
Re: things are eq? but not generated at the same time
Ian Price ianpric...@googlemail.com writes: anyway. Anyway if vectors are immutable, as I believe they are, it I, of course, meant vector literals, but a quick test shows this is not the case. (define v #(1 2 3)) (pk v) (vector-set! v 0 #f) (pk v) ~ $ guile -s /tmp/test.scm ;;; (#(1 2 3)) ;;; (#(#f 2 3)) Hmm, the sharing is indeed a problem then. -- Ian Price -- shift-reset.com Programming is like pinball. The reward for doing it well is the opportunity to do it again - from The Wizardy Compiled
Re: things are eq? but not generated at the same time
Yes, I can agree om that. But this should be very stated clearly and perhaps added to a pitfall's section. /Stefan On Wed, Sep 5, 2012 at 9:13 PM, Ian Price ianpric...@googlemail.com wrote: Stefan Israelsson Tampe stefan.ita...@gmail.com writes: Is this an optimization we need. I can figure out applications where you do not want this behavior e.g. I wan't to make distinct objects and add metadata by making a vector of it. Now different objects might have the same metadata and now go against my intuition and coerce the objects. I'm not sure I understand what you are trying to say, make vector of what, the distinct objects? Then you can't do that as a vector literal anyway. Anyway if vectors are immutable, as I believe they are, it doesn't really harm to make them eq? If you want distinctness and mutability, you can always call the vector constructor. -- Ian Price -- shift-reset.com Programming is like pinball. The reward for doing it well is the opportunity to do it again - from The Wizardy Compiled
Re: things are eq? but not generated at the same time
Ian Price ianpric...@googlemail.com skribis: Ian Price ianpric...@googlemail.com writes: anyway. Anyway if vectors are immutable, as I believe they are, it I, of course, meant vector literals, but a quick test shows this is not the case. It could be the case, though. Literal strings are already immutable, for instance. Ludo’.
Re: things are eq? but not generated at the same time
Hi, Stefan Israelsson Tampe stefan.ita...@gmail.com skribis: If I put, (define a #(1)) (define b #(1)) , load the file. Then (eq? a b) #t The R5RS reads (info (r5rs) Equivalence predicates): Since it is an error to modify constant objects (those returned by literal expressions), implementations are permitted, though not required, to share structure between constants where appropriate. And then, these examples: (eq? '(a) '(a))== _unspecified_ (eq? a a) == _unspecified_ (eq? )== _unspecified_ So no problem here, AFAICS. Ludo’.