Re: Magic Literal instances
On 2009-04-26, at 4:16 AM, spir wrote:
> 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?
There is an internal symbol hash table in the IoState. When the append
method creates the new character array, it looks to see if there is
already a symbol with the same string, if so it will return it and
discard the temporary array. If not, it will create a new symbol using
the array.
Btw, a Symbol is just an immutable Sequence and Sequences can contain
any of the standard C data types. So you could do things like have a
Symbol containing a vector of 64 bit floats, etc.
- Steve