News for hackers. Stuff that matters.
Re:Ask HN: Your favorite syntactic sugar from any language? by artemisyna on Friday June 15, 2018 @06:42PM (#17324303)
Haskell has way too much syntactic sugar some of the time, but I really appreciate its anonymous function syntax.

If I need a quick-and-dirty map over a list of something, a

  (\x -> x + 1) a
is much nicer than a

  std::for_each(a.start(), a.end(),
   [](float x) {  
            return x + 1;  
        } // end of lambda expression  
   )
or whatnot that I have to do in C++.
Re:Ask HN: Your favorite syntactic sugar from any language? by nicoburns on Friday June 15, 2018 @07:19PM (#17324562)
JavaScript lets you do:

a.map(x => x + 1)

which is pretty nice. And Rust lets you do:

a.map(|x| x + 1)

C++ syntax is just awful, and especially for functional stuff.

Re:Ask HN: Your favorite syntactic sugar from any language? by himom on Friday June 15, 2018 @08:29PM (#17324939)
Swift closure syntax, at least in <= 2.0, made for awkward API calls, since it wasn’t clear whether inline or after closures were used.

In Ruby,

    a.map(&:succ)
Re:Ask HN: Your favorite syntactic sugar from any language? by steveklabnik on Friday June 15, 2018 @08:36PM (#17324981)
If you have a named function, rust lets you do

    a.map(succ)
as well, since functions can be used where closures can, as long as the types work.
Re:Ask HN: Your favorite syntactic sugar from any language? by jeffmcmahan on Friday June 15, 2018 @08:51PM (#17325062)
Same in JS
Re:Ask HN: Your favorite syntactic sugar from any language? by stochastic_monk on Friday June 15, 2018 @07:06PM (#17324481)
You're really looking for `std::transform`. On the other hand,

    for(auto it(a.start()); it < a.end(); ++(*it++));
and

    for(auto &el: a) ++el;
aren't terribly verbose.
Re:Ask HN: Your favorite syntactic sugar from any language? by erik_seaberg on Friday June 15, 2018 @10:04PM (#17325369)
I'm still surprised Haskell is the only language I've ever seen in which the "add 1 to your argument" function is simply

  (+ 1)