DIP1001: DoExpression

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 6 07:12:17 PDT 2016


On 9/3/16 12:03 PM, Jonathan M Davis via Digitalmars-d wrote:
> On Saturday, September 03, 2016 14:42:34 Cauterite via Digitalmars-d wrote:
>> On Saturday, 3 September 2016 at 14:25:49 UTC, rikki cattermole
>>
>> wrote:
>>> I propose a slight change:
>>> do(x, y, return z)
>>
>> Hmm, I suppose I should mention one other motivation behind this
>> DIP:
>>
>> I really like to avoid using the 'return' keyword inside
>> expressions, because I find it visually confusing - hear me out
>> here -
>> When you're reading a function and trying to understand its
>> control flow, one of the main elements you're searching for is
>> all the places the function can return from.
>> If the code has a lot of anonymous functions with return
>> statements this can really slow down the process as you have to
>> more carefully inspect every return to see if it's a 'real'
>> return or inside an anonymous function.
>>
>> Also, in case it wasn't obvious, the do() syntax was inspired by
>> Clojure:
>> http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/do
>
> So, instead of having the return statement which everyone knows to look for
> and is easy to grep for, you want to add a way to return _without_ a return
> statement?

No, the amendment is to show that z is the "return" of the do 
expression. It doesn't return from the function the do expression is in.

I also think that a) we shouldn't have a requirement, or support for, 
return inside the expression -- return is not actually an expression, 
it's a statement. This would be very confusing. b) I like the idea of 
the semicolon to show that the last expression is different.

I'm not sure I agree with the general principal of the DIP though. I've 
never liked comma expressions, and this seems like a waste of syntax. 
Won't tuples suffice here when they take over the syntax? e.g. (x, y, 
z)[$-1]

-Steve


More information about the Digitalmars-d mailing list