# How +:symbol is parsed

**URL:** <https://www.ruby-forum.com/t/how-symbol-is-parsed/112533>\
**Category:** Ruby\
**Created:** [August 20, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533 "2007-08-20T18:40:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [August 20, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533/1 "2007-08-20T18:40:47Z")

</div>

Hi.

I wanted to be evil and add my own custom semantics to +:some\_symbol  
constructs. But I’ve found such consctructs doesn’t call Symbol#+@,  
while  
+(:some\_symbol) does call.

I can suppose it’s reason of numbers construction in parser

+3 #doesn’t calls Fixnum#+@, it’s like Finxum.new(+3),  
+(3) #does calls Fixnum#+@, it’s like Fixnum.new(3).+@

but it’s still strange for me this rule works for symbols too (but not  
for  
strings, +“test” calls String#+@). Can somebody please explain this  
strangeness?

Thanks.

V.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [August 21, 2007, 12:23am UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533/2 "2007-08-21T00:23:39Z")

</div>

On 8/20/07, Victor Zverok S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but it’s still strange for me this rule works for symbols too (but not for  
> strings, +“test” calls String#+@). Can somebody please explain this  
> strangeness?
> 
> Thanks.
> 
> V.

Well, I haven’t looked at parse.y, but I’ll wager that the difference  
between 3 and “test” is that, for numeric literals, a preceding + or -  
is considered the sign of the literal number. That is, +3 is a number  
all by itself, whereas +“test” doesn’t make sense unless the + is a  
method call. There’s also no method call when a number is in  
exponential notation like -4.3e+11 .

In ruby-ancient times, a symbol was more like an integer, which may or  
may not explain the +:symbol semantics.

-A

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [August 22, 2007, 4:00pm UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533/3 "2007-08-22T16:00:25Z")

</div>

Hi,

In message “Re: How +:symbol is parsed”  
on Tue, 21 Aug 2007 01:39:00 +0900, “Victor "Zverok" Shepelev”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|I wanted to be evil and add my own custom semantics to +:some\_symbol  
|constructs. But I’ve found such consctructs doesn’t call Symbol#+@, while  
|+(:some\_symbol) does call.

For historical reason, + before literals works as “identity” (the  
function that returns the argument). This behavior will be fixed in  
the future, but not for 1.8.x, sorry.

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [August 22, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533/4 "2007-08-22T16:20:27Z")

</div>

From: Yukihiro M. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
Sent: Wednesday, August 22, 2007 4:59 PM

> function that returns the argument). This behavior will be fixed in  
> the future, but not for 1.8.x, sorry.

OK. It wasn’t “bug report” (as incorporating +:symbol semantics is  
mostly  
evil, in any case), it was just “request for understanging”.

V.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [August 23, 2007, 12:53am UTC](https://www.ruby-forum.com/t/how-symbol-is-parsed/112533/5 "2007-08-23T00:53:27Z")

</div>

Yukihiro M. wrote:

> |I wanted to be evil and add my own custom semantics to +:some\_symbol  
> |constructs. But I’ve found such consctructs doesn’t call Symbol#+@, while  
> |+(:some\_symbol) does call.
> 
> For historical reason, + before literals works as “identity” (the  
> function that returns the argument). This behavior will be fixed in  
> the future, but not for 1.8.x, sorry.

If you have time, would you care to enlighten us on what the historial  
cirumstances were? I just love history. So full of interesting nooks and  
crannies. 🙂

Daniel
