Re: [swift-evolution] [Pitch] Contextual variables

2017-07-03 Thread Dimitri Racordon via swift-evolution
Actually, Brent’s solution is quite satisfactory. It is slightly more heavy on the syntax, but I couldn't agree more that changing the language should be about more than mere syntactic sugars. Swift is already quite furnished in that department ;) Thanks for your time. Best, Dimitri PS: I do

Re: [swift-evolution] [Pitch] Contextual variables

2017-07-02 Thread rintaro ishizaki via swift-evolution
Ughh, my bad, let me withdraw this idea: func saveAndRestore(_ variable: inout T, _ tmpVal: T, body: () -> R) -> R { let savedVal = variable variable = tmpVal defer { variable = savedVal } return body() } var contextVal: Int = 0saveAndRestore(, 1) { print(contextVal) }

Re: [swift-evolution] [Pitch] Contextual variables

2017-07-02 Thread rintaro ishizaki via swift-evolution
2017-07-03 11:23 GMT+09:00 rintaro ishizaki via swift-evolution < swift-evolution@swift.org>: > > > 2017-06-28 21:33 GMT+09:00 Dimitri Racordon via swift-evolution < > swift-evolution@swift.org>: > >> Hello community! >> >> I’d like to pitch an idea for a user-friendly way for functions to pull

Re: [swift-evolution] [Pitch] Contextual variables

2017-07-02 Thread rintaro ishizaki via swift-evolution
2017-06-28 21:33 GMT+09:00 Dimitri Racordon via swift-evolution < swift-evolution@swift.org>: > Hello community! > > I’d like to pitch an idea for a user-friendly way for functions to pull > values from an arbitrary environment. Let me introduce the concept with a > motivational example before I

Re: [swift-evolution] [Pitch] Contextual variables

2017-07-02 Thread Brent Royal-Gordon via swift-evolution
> On Jun 28, 2017, at 5:33 AM, Dimitri Racordon via swift-evolution > wrote: > > Using our contextual variables, one could rewrite our motivational example as > follows: > > class Interpreter: Visitor { > func visit(_ node: BinExpr) { > let lhs, rhs :

[swift-evolution] [Pitch] Contextual variables

2017-06-28 Thread Dimitri Racordon via swift-evolution
Hello community! I’d like to pitch an idea for a user-friendly way for functions to pull values from an arbitrary environment. Let me introduce the concept with a motivational example before I dig into dirty syntax and semantics. Note that I intentionally removed many pieces of code from my