I'm really glad that EcmaScript 6 has promises built into the language, but the syntax will still be quite wordy:

new Promise(f).then(r => {
}).then(r2 => 

I'm just wondering if there are any languages that have syntactic sugar for promises, so the result looks more like conventional imperative programming. Maybe hypothetically something like:

fetch f {
get r
get r2

closed as too broad by gnat, durron597, Ixrec, user40980, enderland Oct 18 '15 at 14:10

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I think C#'s async/await does something like this, but I haven't actually used it. – immibis Oct 16 '15 at 5:21
  • async await combined with Task<T>. – Robert Harvey Oct 16 '15 at 6:04
  • Choosing our programming language according to promise syntax, are we? – Neil Oct 16 '15 at 7:10

Yes, there are several such languages:

  • C# has async methods and the await keyword. Technically speaking, any object which implements a certain syntactic pattern can be awaited, but the intention is for this syntax to be used for, well, asynchronous programming, and the only objects in the framework which implement the syntactic pattern are Task<T> objects, which are futures/promises (depending on your exact definition of "future" and "promise", they may be futures, promises, both, or neither).
  • Visual Basic.NET has the same syntax with the same semantics
  • F# has asynchronous workflows, which were the inspiration for async/await
  • In languages with macros, libraries can implement their own syntax (within limits), and so there are promise libraries in Scala, Scheme, Common Lisp, Clojure, and other Lisps, which have what looks like builtin syntax.
  • Python 3.5+ has async / await
  • The next version of ECMAScript will very likely have async/await
  • The next version of C++ may or may not have resumable/await
  • And last but very important: Oz does not have special syntax for promises, because in Oz every variable is a dataflow-variable, and every value is a promise!
  • Wow - thanks for such a complete list. Hadn't heard of async/await. Here's the ES7 spec for it: tc39.github.io/ecmascript-asyncawait/#intro, and some sample code – Steve Bennett Oct 17 '15 at 13:15
  • Just thought of a missing item for this list: as Promises are essentially a monad, Haskell's "do" notation could be considered just such a syntax. Or indeed any other language with a suitable monad building syntax. – Jules Jan 19 '16 at 21:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.