Questions tagged [syntactic-sugar]

For questions relating to syntactic sugar, or syntax that makes certain operations easier to express, in a programming language.

Filter by
Sorted by
Tagged with
5 votes
1 answer
162 views

Possible ways to determine reach of implicit lambda expressions

When defining an inline function, even the shortest way to do so usually requires naming its argument (unless you're going for the point-free style and you have an expression that returns a function). ...
Lazar Ljubenović's user avatar
21 votes
4 answers
5k views

Why do many template languages have `for-else` statements?

I've noticed that many template engines have a mechanism for detecting that a loop is not occurring. Although their names and syntax vary, they all have this similar structure. For example: Jinja <...
Aster's user avatar
  • 2,688
7 votes
5 answers
569 views

Declaring infix operators like Haskell's in other languages?

Haskell has support for declaring custom infix operators, including their precedence and associativity. In addition, any identifier can be used as binary infix operator by placing it between ...
Christian Lindig's user avatar
16 votes
2 answers
1k views

What are the other potential downsides, if any, of making `<$>` and `<*>` (but not `pure`) implicit?

Here, <$> is the infix functor map operation with type Functor f => (a -> b) -> f a -> f b for any functor ...
Wheelwright's user avatar
3 votes
3 answers
212 views

What are pros and cons of adding special syntactic sugar for decorators? [closed]

Some languages have syntactic sugar for decorators (like Python), but some languages do not (like Go). PSL Some languages do not have decorators at all. So, what are pros and cons of syntactic sugar ...
nchistov's user avatar
  • 1,585
12 votes
5 answers
868 views

Prior art on pipelines of function calls

Say I have a loop that looks like this: for i in range(1, 10) { print(i) } Now I want to take the same sequence in reverse, and filter out even numbers. I might ...
Rob N's user avatar
  • 1,073
2 votes
3 answers
205 views

Pros and cons of generalized `nil`-coalescing operators

Many languages extend their "indexing" operator . to a nil-coalescing variant ?. to deal with indexing chains such as <...
Luatic's user avatar
  • 298
17 votes
5 answers
1k views

What are the downsides of supporting chained comparison operators?

Some languages, such as Python, support chaining comparison operators, such that x < y < z is equivalent to ...
Rydwolf Programs's user avatar
7 votes
3 answers
514 views

What are the advantages of syntactic sugar and when should it be added?

Many languages have large amounts of syntactic sugar. For example, while working with Python there are seemingly many ways to express the same operations. For example, in list comprehension ...
FireTheLost's user avatar
  • 1,583