Topic: Short-form for function and/or lambda bodies.


Author: andrewtomazos@gmail.com
Date: Tue, 9 Jul 2013 11:47:42 -0700 (PDT)
Raw View
------=_Part_624_4824136.1373395662854
Content-Type: text/plain; charset=ISO-8859-1


As an alternative short-form for defining a function:

    function-body:
        ... // existing bodies
        = expression ;
        = braced-init-list

Where such a form is equivalent to { return expression; } and { return
braced-init-list; } respectively, except where a pure virtual specifier (=
0) would not be ill-formed.  (In cases where `= 0` is well-formed
parenthesis can be used to disambiguate `= (0)`)

So:

    int f(int a, int b) = a + b;

is the same as:

    int f(int a, int b) { return a + b; }

and

    vector<int> g(int a, int b) = {a, b}

is the same as:

    vector<int> g(int a, int b) { return {a, b}; }

Likewise for lambdas maybe:

    lambda-expression:
        lambda-introducer lambda-declarator_opt lambda-body

    lambda-body:
        compound-statement
        = expression
        = braced-init-list

Some thought would have to be given to termination of the `= expression`
case.  Perhaps it can greedily match the longest expression.

But the general idea is the same:

    foo([] = a + b);

is the same as:

    foo([] { return a + b; });

(Inspired from Scala, and the mostly empty syntactic space after
function-declarator=) .

Enjoy,
Andrew.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



------=_Part_624_4824136.1373395662854
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br>As an alternative short-form for defining a function:<br><br>&nbsp;&nbs=
p;&nbsp; function-body:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... /=
/ existing bodies<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D express=
ion ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D braced-init-list<br=
><br>Where such a form is equivalent to { return expression; } and { return=
 braced-init-list; } respectively, except where a pure virtual specifier (=
=3D 0) would not be ill-formed.&nbsp; (In cases where `=3D 0` is well-forme=
d parenthesis can be used to disambiguate `=3D (0)`)<br><br>So:<br><br>&nbs=
p;&nbsp;&nbsp; int f(int a, int b) =3D a + b;<br><br>is the same as:<br><br=
>&nbsp;&nbsp;&nbsp; int f(int a, int b) { return a + b; }<br><br>and<br><br=
>&nbsp;&nbsp;&nbsp; vector&lt;int&gt; g(int a, int b) =3D {a, b}<br><br>is =
the same as:<br><br>&nbsp;&nbsp;&nbsp; vector&lt;int&gt; g(int a, int b) { =
return {a, b}; }<br><br>Likewise for lambdas maybe:<br><br>&nbsp;&nbsp;&nbs=
p; lambda-expression:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lambda-=
introducer lambda-declarator_opt lambda-body<br><br>&nbsp;&nbsp;&nbsp; lamb=
da-body:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; compound-statement<b=
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D expression<br>&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =3D braced-init-list<br><br>Some thought wou=
ld have to be given to termination of the `=3D expression` case.&nbsp; Perh=
aps it can greedily match the longest expression.<br><br>But the general id=
ea is the same:<br><br>&nbsp;&nbsp;&nbsp; foo([] =3D a + b);<br><br>is the =
same as:<br><br>&nbsp;&nbsp;&nbsp; foo([] { return a + b; });<br><br>(Inspi=
red from Scala, and the mostly empty syntactic space after function-declara=
tor=3D) .<br><br>Enjoy,<br>Andrew.<br><br>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_624_4824136.1373395662854--

.


Author: sgheeren@gmail.com
Date: Tue, 9 Jul 2013 13:38:27 -0700 (PDT)
Raw View
------=_Part_2090_799305.1373402307871
Content-Type: text/plain; charset=ISO-8859-1



On Tuesday, July 9, 2013 8:47:42 PM UTC+2, andrew...@gmail.com wrote:
>
>
> As an alternative short-form for defining a function:
>
> You do realize this is C++, and having too few alternative syntax
construct is not one of the main language impediments?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



------=_Part_2090_799305.1373402307871
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Tuesday, July 9, 2013 8:47:42 PM UTC+2, andrew...@gmail.com wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><br>As an alternative short-=
form for defining a function:<br><br></blockquote><div>You do realize this =
is C++, and having too few alternative syntax construct is not one of the m=
ain language impediments?&nbsp;</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2090_799305.1373402307871--

.