« Return to Thread: Literal instance slots, 10 foo := 1

Re: Magic Literal instances

by spir :: Rate this Message:

Reply to Author | View in Thread

Le Sun, 26 Apr 2009 02:28:20 -0700,
Steve Dekorte <steve@...> s'exprima ainsi:

>
> On 2009-04-26, at 2:13 AM, spir wrote:
> > (works also for longer strings)
> > How come literal values can be shared? Have the impression I must be  
> > messing up distinct things -- or overlooking something obvious.
>
> String literals are symbols. Symbols are global and there is only one  
> instance of each. Even if a symbol isn't referenced, it will live  
> until the garbage collector removes it. For example:
>
> Io> "foo" uniqueId
> ==> 6564192
> Io> "foo" uniqueId
> ==> 6564192
> Io> Collector collect
> ==> 5196
> Io> "foo" uniqueId
> ==> 5405424
>

Thank you.
There's still something I don't get.

Io> "foofoo" attr := 7
==> 7
Io> s = "foo" .. "foo" ; s attr
==> 7

Io> "foofoo" uniqueId
==> 158710360
Io> s = "foo" .. "foo" ; s uniqueId
==> 158710360

How does Io proceed to keep a single instance of "foofoo" in such a case? How does it "know" there is already a "foofoo" somewhere?
Also, does this apply to all literals?

Denis
------
la vita e estrany

 « Return to Thread: Literal instance slots, 10 foo := 1