[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

The symbol dilemma...

Mayuresh Kathe

8/18/2008 10:24:00 AM

Hi,

There's one more thing, I also read the following statements;
---
Ruby's hashes can use any object as a key, but Symbol objects are the
most commonly
used. Symbols are immutable, interned strings. They can be compared by identity
rather than by textual content (because two distinct Symbol objects
will never have the
same content).
---

The statement, "because two distinct Symbol objects will never have
the same content" seems unclear to me.

Can't I do the following?
books = {
:excellent => "Iacocca",
:good => "Freakonomics",
:bad => "The World is Flat",
:ugly => "Guns, Germs and Steel",
:sick => "Guns, Germs and Steel"
}

In that case, won't two distinct Symbol objects, i.e. :ugly, and :sick
have the same content?

I'm sure there's something wrong in the way I'm understanding this,
could someone please elaborate?

Thanks,

~Mayuresh

4 Answers

Farrel Lifson

8/18/2008 10:30:00 AM

0

2008/8/18 Mayuresh Kathe <kathe.mayuresh@gmail.com>:
> The statement, "because two distinct Symbol objects will never have
> the same content" seems unclear to me.
>
> Can't I do the following?
> books = {
> :excellent => "Iacocca",
> :good => "Freakonomics",
> :bad => "The World is Flat",
> :ugly => "Guns, Germs and Steel",
> :sick => "Guns, Germs and Steel"
> }
>
> In that case, won't two distinct Symbol objects, i.e. :ugly, and :sick
> have the same content?
>
> I'm sure there's something wrong in the way I'm understanding this,
> could someone please elaborate?

The symbols themselvs (:ugly and :sick) will always be distinct, not
the strings they act as keys for in the hash.

Farrel
--
Aimred - Ruby Development and Consulting
http://www....

James Coglan

8/18/2008 10:35:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

>
> > Can't I do the following?
> > books = {
> > :excellent => "Iacocca",
> > :good => "Freakonomics",
> > :bad => "The World is Flat",
> > :ugly => "Guns, Germs and Steel",
> > :sick => "Guns, Germs and Steel"
> > }
> >
> > In that case, won't two distinct Symbol objects, i.e. :ugly, and :sick
> > have the same content?
> >
> > I'm sure there's something wrong in the way I'm understanding this,
> > could someone please elaborate?
>
> The symbols themselvs (:ugly and :sick) will always be distinct, not
> the strings they act as keys for in the hash.



More precisely, symbols with same value are shared and point to the same
objects in memory:

> syms = [:foo, :bar, :baz, :foo, :baz]
> syms.map { |s| s.object_id }
=> [148818, 161538, 161618, 148818, 161618]

So, if two symbols have the same value, they are actually the very same
object in memory. Therefore, two distinct Symbol objects must have different
values.

Joost Diepenmaat

8/18/2008 10:40:00 AM

0

Mayuresh Kathe <kathe.mayuresh@gmail.com> writes:

> The statement, "because two distinct Symbol objects will never have
> the same content" seems unclear to me.
>
> Can't I do the following?
> books = {
> :excellent => "Iacocca",
> :good => "Freakonomics",
> :bad => "The World is Flat",
> :ugly => "Guns, Germs and Steel",
> :sick => "Guns, Germs and Steel"
> }
>
> In that case, won't two distinct Symbol objects, i.e. :ugly, and :sick
> have the same content?

No, :ugly refers to ("has the content of") the symbol :ugly, and :sick
refers to the symbol :sick. The fact that you're using different
symbols as keys to equal values in some hash is irreleveant. What's
meant by the original statement is:

There are no two symbols ! :x.equal?(:y) where :x.eql?(:y)

--
Joost Diepenmaat | blog: http://joost.... | work: http://...

Sancho Panza

6/21/2014 2:56:00 PM

0

On 6/20/2014 9:49 PM, RichTrasky wrote:
> Sancho Panza wrote:
>>
>> On 6/18/2014 12:40 AM, RichTrasky wrote:
>>> Sancho Panza wrote:
>>>>
>>>> On 6/15/2014 11:21 PM, RichTrasky wrote:
>>>>> Sancho Panza wrote:
>>>>>>
>>>>>> On 6/13/2014 10:44 PM, RichTrasky wrote:
>>>>>>> Sancho Panza wrote:
>>>>>>>>
>>>>>>>> On 6/10/2014 11:37 PM, RichTrasky wrote:
>>>>>>>>> Sancho Panza wrote:
>>>>>>>>>>
>>>>>>>>>> On 6/8/2014 10:46 PM, RichTrasky wrote:
>>>>>>>>>>> Sancho Panza wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> On 6/6/2014 10:27 PM, RichTrasky wrote:
>>>>>>>>>>>>> Sancho Panza wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On 6/3/2014 10:53 PM, RichTrasky wrote:
>>>>>>>>>>>>>>> Sancho Panza wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On 6/1/2014 9:21 PM, RichTrasky wrote:
>>>>>>>>>>>>>>>>> Sancho Panza wrote:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> On 5/20/2014 11:40 PM, Carpathian Wallaby wrote:
>>>>>>>>>>>>>>>>>>> mobile traveler wrote:
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> On 5/16/2014 8:43 PM, RichTrasky wrote:
>>>>>>>>>>>>>>>>>>>>> Obama's next fiasco will be the OPEC embargo of a few decades ago
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Does he have to wait until he's through playing mid-term shell games
>>>>>>>>>>>>>>>>>>>> with Keystone XL?
>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>> Or can he get after it now?
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>> We don't need Keystone. We're beating the ME in production.
>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> That must be why crude is over $100 a barrel and gasoline is running up
>>>>>>>>>>>>>>>>>> to $4 a gallon.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Tell that to the oil companies.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> The oil companies don't set production quotas.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> So?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The price is a function of supply and demand. U.S. demand is down.
>>>>>>>>>>>>>> Governments are controlling supply. Basic economics.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Why is production up then?
>>>>>>>>>>>>>
>>>>>>>>>>>> Cite?
>>>>>>>>>>>
>>>>>>>>>>> http://www.examiner.com/article/u-s-forecasted-to-soon-takeover-as-the-world-s-top-oi...
>>>>>>>>>>> October 24, 2012
>>>>>>>>>>> U.S. oil output is surging so fast that the U.S. could soon overtake Saudi
>>>>>>>>>>> Arabia as the world's biggest producer, according to experts.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> http://online.wsj.com/article/SB100014241278873240495045785416019099...
>>>>>>>>>>> Updated June 12, 2013
>>>>>>>>>>> U.S. crude-oil production grew by more than one million barrels a day last
>>>>>>>>>>> year, the largest increase in the world and the largest in U.S. history
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> http://www.tulsaworld.com/business/energy/harold-hamm-touts-oklahoma-s-growing-oil-production/article_2a2250cc-e228-56bd-9b78-002873c...
>>>>>>>>>>> Jun 7, 2014.
>>>>>>>>>>> Oklahoma is poised to cash in from the ongoing U.S. oil boom, according
>>>>>>>>>>> to one of the nation?s foremost experts on the topic.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> http://www.bloomberg.com/news/2014-05-14/shale-boom-sends-u-s-crude-output-to-28-year...
>>>>>>>>>>>
>>>>>>>>>>> U.S. crude production climbed to a 28-year high last week as the
>>>>>>>>>>> shale boom moved the world?s biggest oil-consuming country closer
>>>>>>>>>>> to energy independence.
>>>>>>>>>>> ...
>>>>>>>>>>> The U.S. met 87 percent of its energy needs in 2013, and 90 percent
>>>>>>>>>>> in December, the most since March 1985, according to the EIA, the
>>>>>>>>>>> statistical arm of the Energy Department.
>>>>>>>>>>> ...
>>>>>>>>>>>
>>>>>>>>>>> Do keep up next time.
>>>>>>>>>>>
>>>>>>>>>> Do try to read next time. Crude oil is a fungible global commodity. That
>>>>>>>>>> is why the statement said, "GovernmentSSSSSSS" ARE controlling supply.
>>>>>>>>>> Do try to be responsive before shooting off a cheap insult.
>>>>>>>>>
>>>>>>>>> PRODUCTION. In the US. Got that?
>>>>>>>>>
>>>>>>>> Goalpost move noted.
>>>>>>>
>>>>>>> Goalpost restored.
>>>>>>>
>>>>>>> "U.S. crude production climbed to a 28-year high"
>>>>>>>
>>>>>>> No mention there of any government.
>>>>>>>
>>>>>> Regulation of energy industries by all governments needs no mentions. It
>>>>>> is a given. Like the rising and setting of the Sun.
>>>>>
>>>>> Show is where the government set production levels ->
>>>>>
>>>> Which government are you talking about?
>>>
>>> From the context above, take a guess.
>>>
>>> Hint - you're living in it...
>>>
>> Seeing as how you are pathetically unable to deal with the question as
>
> Seeing as how you are pathetically clueless...
>
>
> Show is where the government set production levels ->
>
It was what you snipped and clearly don't even pretend to have looked
at. The government has been refusing to allow drilling and production on
its immense landholdings. "Oil as a fungible global commodity and [you]
insist on a particularly circumscribed case that you are trying to
tailor to meet your agenda, here is just one major way in which the U.S.
government regulates oil production. The U.S. government has made no
secret of its intent to raise prices like those for gasoline and to fix
markets like that for coal power. Let's see your backup to show that the
U.S. oil industry is entirely unregulated."




---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www...