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

Re: Magic Literal instances

by quercerandjanath :: Rate this Message:

Reply to Author | View in Thread

--- In iolanguage@..., Steve Dekorte <steve@...> wrote:

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

I like this behaviour, and it doesn't seem at all like magic to me.  It seems more consistent than the way other languages treat literals.  Literals in Io work just like other objects.  Good!

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