unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* things are eq? but not generated at the same time
@ 2012-09-05 18:44 Stefan Israelsson Tampe
  2012-09-05 19:13 ` Ian Price
  2012-09-05 21:58 ` Ludovic Courtès
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-09-05 18:44 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 522 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 598 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 18:44 things are eq? but not generated at the same time Stefan Israelsson Tampe
@ 2012-09-05 19:13 ` Ian Price
  2012-09-05 19:24   ` Ian Price
  2012-09-05 19:27   ` Stefan Israelsson Tampe
  2012-09-05 21:58 ` Ludovic Courtès
  1 sibling, 2 replies; 7+ messages in thread
From: Ian Price @ 2012-09-05 19:13 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

Stefan Israelsson Tampe <stefan.itampe@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"



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 19:13 ` Ian Price
@ 2012-09-05 19:24   ` Ian Price
  2012-09-05 21:54     ` Ludovic Courtès
  2012-09-11 17:06     ` Chris K. Jester-Young
  2012-09-05 19:27   ` Stefan Israelsson Tampe
  1 sibling, 2 replies; 7+ messages in thread
From: Ian Price @ 2012-09-05 19:24 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

Ian Price <ianprice90@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"



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 19:13 ` Ian Price
  2012-09-05 19:24   ` Ian Price
@ 2012-09-05 19:27   ` Stefan Israelsson Tampe
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Israelsson Tampe @ 2012-09-05 19:27 UTC (permalink / raw)
  To: Ian Price; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]

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 <ianprice90@googlemail.com> wrote:

> Stefan Israelsson Tampe <stefan.itampe@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"
>

[-- Attachment #2: Type: text/html, Size: 1658 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 19:24   ` Ian Price
@ 2012-09-05 21:54     ` Ludovic Courtès
  2012-09-11 17:06     ` Chris K. Jester-Young
  1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2012-09-05 21:54 UTC (permalink / raw)
  To: guile-devel

Ian Price <ianprice90@googlemail.com> skribis:

> Ian Price <ianprice90@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’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 18:44 things are eq? but not generated at the same time Stefan Israelsson Tampe
  2012-09-05 19:13 ` Ian Price
@ 2012-09-05 21:58 ` Ludovic Courtès
  1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2012-09-05 21:58 UTC (permalink / raw)
  To: guile-devel

Hi,

Stefan Israelsson Tampe <stefan.itampe@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’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: things are eq? but not generated at the same time
  2012-09-05 19:24   ` Ian Price
  2012-09-05 21:54     ` Ludovic Courtès
@ 2012-09-11 17:06     ` Chris K. Jester-Young
  1 sibling, 0 replies; 7+ messages in thread
From: Chris K. Jester-Young @ 2012-09-11 17:06 UTC (permalink / raw)
  To: guile-devel

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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-09-11 17:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-05 18:44 things are eq? but not generated at the same time Stefan Israelsson Tampe
2012-09-05 19:13 ` Ian Price
2012-09-05 19:24   ` Ian Price
2012-09-05 21:54     ` Ludovic Courtès
2012-09-11 17:06     ` Chris K. Jester-Young
2012-09-05 19:27   ` Stefan Israelsson Tampe
2012-09-05 21:58 ` Ludovic Courtès

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).