[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: where does the syntactic sugar get defined?

Victor 'Zverok' Shepelev

5/22/2007 7:54:00 AM

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Key Bern
Sent: Tuesday, May 22, 2007 10:49 AM
>Where exactly does the syntactic sugar get defined in Ruby? Is it
>built-in into the Ruby core syntax? It seems to me like a preprocessing
>thing...
>
>Can I define my own syntactic sugar for Ruby?
>

Definition of what is "core" and what is "sugar" is more theoretical than
practical. Different parts of language can be seen as one or another
depending on point of view.

If you would narrow your question (what constructs are you talking about),
you can receive more concrete answer.

V.


3 Answers

Key Bern

5/22/2007 8:03:00 AM

0

core syntax vs syntactic sugar
----------- ---------------
4.+(12) 4 + 12
array.[ ](13) array[13]
persoon1.==(persoon2) persoon1 == persoon2
if not unless
Proc.new lambda

Aren't the things from to right column preprocessed into the left
column?

--
Posted via http://www.ruby-....

Alex Gutteridge

5/22/2007 8:32:00 AM

0

On 22 May 2007, at 17:03, Key Bern wrote:

> core syntax vs syntactic sugar
> ----------- ---------------
> 4.+(12) 4 + 12
> array.[ ](13) array[13]
> persoon1.==(persoon2) persoon1 == persoon2
> if not unless
> Proc.new lambda
>
> Aren't the things from to right column preprocessed into the left
> column?

'unless' is a full 'reserved word' in the parser just like 'if' and
'not' so I don't think it's really correct to say it is being
preprocessed into them. Likewise operators such as '+' and '==' are
defined in parse.y. lambda and Proc.new are not identical. The
behaviour of lambda is defined in eval.c.

Alex Gutteridge

Bioinformatics Center
Kyoto University



Logan Capaldo

5/22/2007 4:40:00 PM

0

On Tue, May 22, 2007 at 05:03:04PM +0900, Key Bern wrote:
> core syntax vs syntactic sugar
> ----------- ---------------
> 4.+(12) 4 + 12
Yes
> array.[ ](13) array[13]
Yes
> persoon1.==(persoon2) persoon1 == persoon2
Yes
> if not unless
Yes (If you don't believe me, check parse tree's AST for an unless cond then
...)
> Proc.new lambda
No

One more:
!(a == b) a != b

Of course these things only apply for MRI, JRuby, etc. may do different
transformations, I do not know.
>
> Aren't the things from to right column preprocessed into the left
> column?
>
> --
> Posted via http://www.ruby-....