lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> On Wed, Jun 11, 2014 at 8:44 AM, Luiz Henrique de Figueiredo <
> lhf@tecgraf.puc-rio.br> wrote:
> 
> > Wikipedia's page on that seems suitable:
> >         http://en.wikipedia.org/wiki/Syntactic_sugar
> >
> 
> Yes.
> 
> > Specifically, a construct in a language is called syntactic sugar if it
> can be removed from the language without any effect on what the language
> can do: functionality and expressive power will remain the same. For
> instance, in the C language the a[i] notation is syntactic sugar for *(a +
> i).[1]

I (and I believe most people that work with programming languages)
disagree with that definition. Almost anything can be removed from
a language without any effect on what the language can do: function
definitions (just expand the code inline), parameters (idem), local
variables (use globals with proper names), etc.

The more accepted definition is that a syntactical sugar is a
construction that can be changed to something else locally, using only
**syntactical** means (that is, without any kind of analysis of the code,
or without any "context", and is always correct).  In C, a[i] is sugar
for *(a + i) because a[i] can be immediately translated to *(a + i) when
parsed, no matter what is 'a' or 'i'. A while is not a pure sugar for a
construction with gotos because of 'break'. (Sometimes, we use the term
"syntactical sugar" more loosely, disregarding some corner cases like a
'break' in a 'while', but it is important to know the difference.)

-- Roberto