Topic: Introduction of a lambda Keyword


Author: "dr.mephphisto via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Sat, 8 Dec 2018 03:25:04 -0800 (PST)
Raw View
------=_Part_1130_1549252167.1544268304455
Content-Type: multipart/alternative;
 boundary="----=_Part_1131_1483277832.1544268304455"

------=_Part_1131_1483277832.1544268304455
Content-Type: text/plain; charset="UTF-8"

So as Lambda expressions in c++ can be tricked into having state:

> int counter = 0;
> int incr(){
> return counter++;
> }
> int main() {
> auto glambda = []() { return incr(); };
> std::cout << glambda() << std::endl
> return 0;
> }


I thought about how to give a guarantee that a method is a pure, stateless
mathematical function.
 Ideally, this should work for both lambda expressions and normal methods.

My idea was to introduce a lambda keyword for methods.
This keyword would guarantee that the method does not have state.
And tell the Compiler to verify that or throw a compile-time error.

Rules for "lambda" methods would be:

   - Variables:
      - Only arguments
      - and Local Variables
      - and  all constants
   - Methods:
      - Only functions that are "lambda" themselves must be used
      - except for assignments like
         - a=2;
         - a+=1;
         - a++;
      - Pointer:
      - Only unique pointers can be used
      - So Pointer must be passed via move semantic
   - References:
      - Can not be used as that would allow another thread to alter the
      value during execution.
      - the exception are references to constants
   - Objects:
      - Basically, all the rules above apply
      -  The object must be passed as unique pointer via move semantic
      - Only pure functions of the object are accessible.
      - assignments are only allowed to local Objects
      - static classes can always be passed their variables and methods are
      treated as described above.
      - Constant objects are allowed.

This would allow to flag vast parts of standard methods as lambda (e.g.
operator_+ ...). Then one could ensure that at least a subpart of his
program is pure functional and guaranteed not to cause race conditions.



Best Regards Jakob

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/41e17225-b339-4a37-8722-832ec85a85e6%40isocpp.org.

------=_Part_1131_1483277832.1544268304455
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">So as Lambda expressions in c++ can be tricked into having=
 state:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0=
..8ex; border-left-width: 1px; border-left-style: solid; border-left-color: =
rgb(204, 204, 204); padding-left: 1ex;"><table class=3D"highlight tab-size =
js-file-line-container" data-tab-size=3D"8" style=3D"box-sizing: border-box=
; border-collapse: collapse; tab-size: 8; caret-color: rgb(36, 41, 46); col=
or: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &quot;=
Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;=
, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;=
"><tbody style=3D"box-sizing: border-box;"><tr style=3D"box-sizing: border-=
box;"><td id=3D"L2" class=3D"blob-num js-line-number" data-line-number=3D"2=
" style=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px;=
 -webkit-user-select: none; color: rgba(27, 31, 35, 0.298039); cursor: poin=
ter; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Me=
nlo, Courier, monospace; font-size: 12px; line-height: 20px; min-width: 50p=
x; text-align: right; vertical-align: top; white-space: nowrap; width: 50px=
;"></td><td id=3D"LC2" class=3D"blob-code blob-code-inner js-file-line" sty=
le=3D"box-sizing: border-box; padding-right: 10px; padding-left: 10px; line=
-height: 20px; position: relative; vertical-align: top; font-family: SFMono=
-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;=
 font-size: 12px; overflow: visible; white-space: pre; word-wrap: normal;">=
<span class=3D"pl-k" style=3D"box-sizing: border-box; color: rgb(215, 58, 7=
3);">int</span> counter =3D <span class=3D"pl-c1" style=3D"box-sizing: bord=
er-box; color: rgb(0, 92, 197);">0</span>;</td></tr><tr style=3D"box-sizing=
: border-box;"><td id=3D"L3" class=3D"blob-num js-line-number" data-line-nu=
mber=3D"3" style=3D"box-sizing: border-box; padding-right: 10px; padding-le=
ft: 10px; -webkit-user-select: none; color: rgba(27, 31, 35, 0.298039); cur=
sor: pointer; font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&=
quot;, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; min-w=
idth: 50px; text-align: right; vertical-align: top; white-space: nowrap; wi=
dth: 50px;"></td><td id=3D"LC3" class=3D"blob-code blob-code-inner js-file-=
line" style=3D"box-sizing: border-box; padding-right: 10px; padding-left: 1=
0px; line-height: 20px; position: relative; vertical-align: top; font-famil=
y: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, m=
onospace; font-size: 12px; overflow: visible; white-space: pre; word-wrap: =
normal;"><span class=3D"pl-k" style=3D"box-sizing: border-box; color: rgb(2=
15, 58, 73);">int</span> <span class=3D"pl-en" style=3D"box-sizing: border-=
box; color: rgb(111, 66, 193);">incr</span>(){</td></tr><tr style=3D"box-si=
zing: border-box;"><td id=3D"L4" class=3D"blob-num js-line-number" data-lin=
e-number=3D"4" style=3D"box-sizing: border-box; padding-right: 10px; paddin=
g-left: 10px; -webkit-user-select: none; color: rgba(27, 31, 35, 0.298039);=
 cursor: pointer; font-family: SFMono-Regular, Consolas, &quot;Liberation M=
ono&quot;, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; m=
in-width: 50px; text-align: right; vertical-align: top; white-space: nowrap=
; width: 50px;"></td><td id=3D"LC4" class=3D"blob-code blob-code-inner js-f=
ile-line" style=3D"box-sizing: border-box; padding-right: 10px; padding-lef=
t: 10px; line-height: 20px; position: relative; vertical-align: top; font-f=
amily: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courie=
r, monospace; font-size: 12px; overflow: visible; white-space: pre; word-wr=
ap: normal;">    <span class=3D"pl-k" style=3D"box-sizing: border-box; colo=
r: rgb(215, 58, 73);">return</span> counter++;</td></tr><tr style=3D"box-si=
zing: border-box;"><td id=3D"L5" class=3D"blob-num js-line-number" data-lin=
e-number=3D"5" style=3D"box-sizing: border-box; padding-right: 10px; paddin=
g-left: 10px; -webkit-user-select: none; color: rgba(27, 31, 35, 0.298039);=
 cursor: pointer; font-family: SFMono-Regular, Consolas, &quot;Liberation M=
ono&quot;, Menlo, Courier, monospace; font-size: 12px; line-height: 20px; m=
in-width: 50px; text-align: right; vertical-align: top; white-space: nowrap=
; width: 50px;"></td><td id=3D"LC5" class=3D"blob-code blob-code-inner js-f=
ile-line" style=3D"box-sizing: border-box; padding-right: 10px; padding-lef=
t: 10px; line-height: 20px; position: relative; vertical-align: top; font-f=
amily: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courie=
r, monospace; font-size: 12px; overflow: visible; white-space: pre; word-wr=
ap: normal;">}</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"L6"=
 class=3D"blob-num js-line-number" data-line-number=3D"6" style=3D"box-sizi=
ng: border-box; padding-right: 10px; padding-left: 10px; -webkit-user-selec=
t: none; color: rgba(27, 31, 35, 0.298039); cursor: pointer; font-family: S=
FMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monos=
pace; font-size: 12px; line-height: 20px; min-width: 50px; text-align: righ=
t; vertical-align: top; white-space: nowrap; width: 50px;"></td><td id=3D"L=
C6" class=3D"blob-code blob-code-inner js-file-line" style=3D"box-sizing: b=
order-box; padding-right: 10px; padding-left: 10px; line-height: 20px; posi=
tion: relative; vertical-align: top; font-family: SFMono-Regular, Consolas,=
 &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 12px; o=
verflow: visible; white-space: pre; word-wrap: normal;">
</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"L7" class=3D"blob=
-num js-line-number" data-line-number=3D"7" style=3D"box-sizing: border-box=
; padding-right: 10px; padding-left: 10px; -webkit-user-select: none; color=
: rgba(27, 31, 35, 0.298039); cursor: pointer; font-family: SFMono-Regular,=
 Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-siz=
e: 12px; line-height: 20px; min-width: 50px; text-align: right; vertical-al=
ign: top; white-space: nowrap; width: 50px;"></td><td id=3D"LC7" class=3D"b=
lob-code blob-code-inner js-file-line" style=3D"box-sizing: border-box; pad=
ding-right: 10px; padding-left: 10px; line-height: 20px; position: relative=
; vertical-align: top; font-family: SFMono-Regular, Consolas, &quot;Liberat=
ion Mono&quot;, Menlo, Courier, monospace; font-size: 12px; overflow: visib=
le; white-space: pre; word-wrap: normal;"><span class=3D"pl-k" style=3D"box=
-sizing: border-box; color: rgb(215, 58, 73);">int</span> <span class=3D"pl=
-en" style=3D"box-sizing: border-box; color: rgb(111, 66, 193);">main</span=
>() {</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"L8" class=3D=
"blob-num js-line-number" data-line-number=3D"8" style=3D"box-sizing: borde=
r-box; padding-right: 10px; padding-left: 10px; -webkit-user-select: none; =
color: rgba(27, 31, 35, 0.298039); cursor: pointer; font-family: SFMono-Reg=
ular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; fon=
t-size: 12px; line-height: 20px; min-width: 50px; text-align: right; vertic=
al-align: top; white-space: nowrap; width: 50px;"></td><td id=3D"LC8" class=
=3D"blob-code blob-code-inner js-file-line" style=3D"box-sizing: border-box=
; padding-right: 10px; padding-left: 10px; line-height: 20px; position: rel=
ative; vertical-align: top; font-family: SFMono-Regular, Consolas, &quot;Li=
beration Mono&quot;, Menlo, Courier, monospace; font-size: 12px; overflow: =
visible; white-space: pre; word-wrap: normal;">    <span class=3D"pl-k" sty=
le=3D"box-sizing: border-box; color: rgb(215, 58, 73);">auto</span> glambda=
 =3D []() { <span class=3D"pl-k" style=3D"box-sizing: border-box; color: rg=
b(215, 58, 73);">return</span> <span class=3D"pl-c1" style=3D"box-sizing: b=
order-box; color: rgb(0, 92, 197);">incr</span>(); };</td></tr><tr style=3D=
"box-sizing: border-box;"><td id=3D"L9" class=3D"blob-num js-line-number" d=
ata-line-number=3D"9" style=3D"box-sizing: border-box; padding-right: 10px;=
 padding-left: 10px; -webkit-user-select: none; color: rgba(27, 31, 35, 0.2=
98039); cursor: pointer; font-family: SFMono-Regular, Consolas, &quot;Liber=
ation Mono&quot;, Menlo, Courier, monospace; font-size: 12px; line-height: =
20px; min-width: 50px; text-align: right; vertical-align: top; white-space:=
 nowrap; width: 50px;"></td><td id=3D"LC9" class=3D"blob-code blob-code-inn=
er js-file-line" style=3D"box-sizing: border-box; padding-right: 10px; padd=
ing-left: 10px; line-height: 20px; position: relative; vertical-align: top;=
 font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo,=
 Courier, monospace; font-size: 12px; overflow: visible; white-space: pre; =
word-wrap: normal;">    std::cout &lt;&lt; <span class=3D"pl-c1" style=3D"b=
ox-sizing: border-box; color: rgb(0, 92, 197);">glambda</span>() &lt;&lt; s=
td::endl</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"L12" clas=
s=3D"blob-num js-line-number" data-line-number=3D"12" style=3D"box-sizing: =
border-box; padding-right: 10px; padding-left: 10px; -webkit-user-select: n=
one; color: rgba(27, 31, 35, 0.298039); cursor: pointer; font-family: SFMon=
o-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace=
; font-size: 12px; line-height: 20px; min-width: 50px; text-align: right; v=
ertical-align: top; white-space: nowrap; width: 50px;"></td><td id=3D"LC12"=
 class=3D"blob-code blob-code-inner js-file-line" style=3D"box-sizing: bord=
er-box; padding-right: 10px; padding-left: 10px; line-height: 20px; positio=
n: relative; vertical-align: top; font-family: SFMono-Regular, Consolas, &q=
uot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 12px; over=
flow: visible; white-space: pre; word-wrap: normal;">    <span class=3D"pl-=
k" style=3D"box-sizing: border-box; color: rgb(215, 58, 73);">return</span>=
 <span class=3D"pl-c1" style=3D"box-sizing: border-box; color: rgb(0, 92, 1=
97);">0</span>;</td></tr><tr style=3D"box-sizing: border-box;"><td id=3D"L1=
3" class=3D"blob-num js-line-number" data-line-number=3D"13" style=3D"box-s=
izing: border-box; padding-right: 10px; padding-left: 10px; -webkit-user-se=
lect: none; color: rgba(27, 31, 35, 0.298039); cursor: pointer; font-family=
: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, mo=
nospace; font-size: 12px; line-height: 20px; min-width: 50px; text-align: r=
ight; vertical-align: top; white-space: nowrap; width: 50px;"></td><td id=
=3D"LC13" class=3D"blob-code blob-code-inner js-file-line" style=3D"box-siz=
ing: border-box; padding-right: 10px; padding-left: 10px; line-height: 20px=
; position: relative; vertical-align: top; font-family: SFMono-Regular, Con=
solas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 1=
2px; overflow: visible; white-space: pre; word-wrap: normal;">}</td></tr></=
tbody></table></blockquote><div>=C2=A0</div>I thought about how to give a g=
uarantee that a method is a pure, stateless mathematical function.<div>=C2=
=A0Ideally, this should work for both lambda expressions and normal methods=
..</div><div><br></div><div>My idea was to introduce a lambda keyword for me=
thods.</div><div>This keyword would guarantee that the method does not have=
 state.</div><div>And tell the Compiler to verify that or throw a compile-t=
ime error.</div><div><br></div><div>Rules for &quot;lambda&quot; methods wo=
uld be:</div><div><ul><li>Variables:</li><ul><li>Only arguments</li><li>and=
 Local Variables</li><li>and =C2=A0all constants</li></ul><li>Methods:</li>=
<ul><li>Only functions that are &quot;lambda&quot; themselves must be used<=
/li><li>except for assignments like=C2=A0</li><ul><li>a=3D2;</li><li>a+=3D1=
;</li><li>a++;</li></ul></ul><li>Pointer:</li><ul><li>Only unique pointers =
can be used=C2=A0</li><li>So Pointer must be passed via move semantic</li><=
/ul><li>References:</li><ul><li>Can not be used as that would allow another=
 thread to alter the value during execution.</li><li>the exception are refe=
rences to constants</li></ul><li>Objects:</li><ul><li>Basically, all the ru=
les above apply</li><li>=C2=A0The object must be passed as unique pointer v=
ia move semantic</li><li>Only pure functions of the object are accessible.<=
/li><li>assignments are only allowed to local Objects</li><li>static classe=
s=C2=A0can always be passed their=C2=A0variables and methods are treated as=
 described above.</li><li>Constant objects are allowed.</li></ul></ul>This =
would allow to flag vast parts of standard methods as lambda (e.g. operator=
_+ ...). Then one could ensure that at least a subpart of his program is pu=
re functional and guaranteed not to cause race conditions.=C2=A0<br><div><b=
r></div></div><div><br></div><div><br></div><div>Best Regards Jakob=C2=A0</=
div></div>

<p></p>

-- <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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/41e17225-b339-4a37-8722-832ec85a85e6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/41e17225-b339-4a37-8722-832ec85a85e6=
%40isocpp.org</a>.<br />

------=_Part_1131_1483277832.1544268304455--

------=_Part_1130_1549252167.1544268304455--

.


Author: inkwizytoryankes@gmail.com
Date: Sat, 8 Dec 2018 14:33:46 -0800 (PST)
Raw View
------=_Part_1076_2038982117.1544308426235
Content-Type: multipart/alternative;
 boundary="----=_Part_1077_296318740.1544308426236"

------=_Part_1077_296318740.1544308426236
Content-Type: text/plain; charset="UTF-8"



On Saturday, December 8, 2018 at 12:25:04 PM UTC+1, Doc Mephi73 wrote:
>
> So as Lambda expressions in c++ can be tricked into having state:
>
>> int counter = 0;
>> int incr(){
>> return counter++;
>> }
>> int main() {
>> auto glambda = []() { return incr(); };
>> std::cout << glambda() << std::endl
>> return 0;
>> }
>
>
> I thought about how to give a guarantee that a method is a pure, stateless
> mathematical function.
>  Ideally, this should work for both lambda expressions and normal methods.
>
> My idea was to introduce a lambda keyword for methods.
> This keyword would guarantee that the method does not have state.
> And tell the Compiler to verify that or throw a compile-time error.
>
> Rules for "lambda" methods would be:
>
>    - Variables:
>       - Only arguments
>       - and Local Variables
>       - and  all constants
>    - Methods:
>       - Only functions that are "lambda" themselves must be used
>       - except for assignments like
>          - a=2;
>          - a+=1;
>          - a++;
>       - Pointer:
>       - Only unique pointers can be used
>       - So Pointer must be passed via move semantic
>    - References:
>       - Can not be used as that would allow another thread to alter the
>       value during execution.
>       - the exception are references to constants
>    - Objects:
>       - Basically, all the rules above apply
>       -  The object must be passed as unique pointer via move semantic
>       - Only pure functions of the object are accessible.
>       - assignments are only allowed to local Objects
>       - static classes can always be passed their variables and methods
>       are treated as described above.
>       - Constant objects are allowed.
>
> This would allow to flag vast parts of standard methods as lambda (e.g.
> operator_+ ...). Then one could ensure that at least a subpart of his
> program is pure functional and guaranteed not to cause race conditions.
>
>
>
> Best Regards Jakob
>

Half of work is done by:
http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4487.pdf
In most cases your code will be rejected but if you add some `if` you can
avoid this as long non-const code is conditionally executed.
Portably correct solution is adding new category of function that can call
only `constexpr` functions, this could be done by attributes because we are
only rejecting valid code.

This could be two attributes: `[[pure]]` and `[[weak_pure]]` (probably
there was already similar proposal).
`[[pure]]` allow only calling other pure functions (this is viral
attribute, because all other function called need have it too)
`[[weak_pure]]` only check if this function call only `constexpr` functions
(that in reality can be not pure at run time).

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/62df37ad-d150-4216-8385-8d88f8597718%40isocpp.org.

------=_Part_1077_296318740.1544308426236
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Saturday, December 8, 2018 at 12:25:04 PM UTC+1=
, Doc Mephi73 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">So as Lambda expressions in c++ can be tricked into having state:<=
br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord=
er-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204=
);padding-left:1ex"><table style=3D"border-collapse:collapse;color:rgb(36,4=
1,46);font-family:-apple-system,BlinkMacSystemFont,&quot;Segoe UI&quot;,Hel=
vetica,Arial,sans-serif,&quot;Apple Color Emoji&quot;,&quot;Segoe UI Emoji&=
quot;,&quot;Segoe UI Symbol&quot;;font-size:14px"><tbody><tr><td style=3D"p=
adding-right:10px;padding-left:10px;color:rgba(27,31,35,0.298039);font-fami=
ly:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monosp=
ace;font-size:12px;line-height:20px;min-width:50px;text-align:right;vertica=
l-align:top;white-space:nowrap;width:50px"></td><td style=3D"padding-right:=
10px;padding-left:10px;line-height:20px;vertical-align:top;font-family:SFMo=
no-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;fon=
t-size:12px;overflow:visible;white-space:pre;word-wrap:normal"><span style=
=3D"color:rgb(215,58,73)">int</span> counter =3D <span style=3D"color:rgb(0=
,92,197)">0</span>;</td></tr><tr><td style=3D"padding-right:10px;padding-le=
ft:10px;color:rgba(27,31,35,0.298039);font-family:SFMono-Regular,Consolas,&=
quot;Liberation Mono&quot;,Menlo,Courier,monospace;font-size:12px;line-heig=
ht:20px;min-width:50px;text-align:right;vertical-align:top;white-space:nowr=
ap;width:50px"></td><td style=3D"padding-right:10px;padding-left:10px;line-=
height:20px;vertical-align:top;font-family:SFMono-Regular,Consolas,&quot;Li=
beration Mono&quot;,Menlo,Courier,monospace;font-size:12px;overflow:visible=
;white-space:pre;word-wrap:normal"><span style=3D"color:rgb(215,58,73)">int=
</span> <span style=3D"color:rgb(111,66,193)">incr</span>(){</td></tr><tr><=
td style=3D"padding-right:10px;padding-left:10px;color:rgba(27,31,35,0.2980=
39);font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,C=
ourier,monospace;font-size:12px;line-height:20px;min-width:50px;text-align:=
right;vertical-align:top;white-space:nowrap;width:50px"></td><td style=3D"p=
adding-right:10px;padding-left:10px;line-height:20px;vertical-align:top;fon=
t-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,=
monospace;font-size:12px;overflow:visible;white-space:pre;word-wrap:normal"=
>    <span style=3D"color:rgb(215,58,73)">return</span> counter++;</td></tr=
><tr><td style=3D"padding-right:10px;padding-left:10px;color:rgba(27,31,35,=
0.298039);font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,M=
enlo,Courier,monospace;font-size:12px;line-height:20px;min-width:50px;text-=
align:right;vertical-align:top;white-space:nowrap;width:50px"></td><td styl=
e=3D"padding-right:10px;padding-left:10px;line-height:20px;vertical-align:t=
op;font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Co=
urier,monospace;font-size:12px;overflow:visible;white-space:pre;word-wrap:n=
ormal">}</td></tr><tr><td style=3D"padding-right:10px;padding-left:10px;col=
or:rgba(27,31,35,0.298039);font-family:SFMono-Regular,Consolas,&quot;Libera=
tion Mono&quot;,Menlo,Courier,monospace;font-size:12px;line-height:20px;min=
-width:50px;text-align:right;vertical-align:top;white-space:nowrap;width:50=
px"></td><td style=3D"padding-right:10px;padding-left:10px;line-height:20px=
;vertical-align:top;font-family:SFMono-Regular,Consolas,&quot;Liberation Mo=
no&quot;,Menlo,Courier,monospace;font-size:12px;overflow:visible;white-spac=
e:pre;word-wrap:normal">
</td></tr><tr><td style=3D"padding-right:10px;padding-left:10px;color:rgba(=
27,31,35,0.298039);font-family:SFMono-Regular,Consolas,&quot;Liberation Mon=
o&quot;,Menlo,Courier,monospace;font-size:12px;line-height:20px;min-width:5=
0px;text-align:right;vertical-align:top;white-space:nowrap;width:50px"></td=
><td style=3D"padding-right:10px;padding-left:10px;line-height:20px;vertica=
l-align:top;font-family:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;=
,Menlo,Courier,monospace;font-size:12px;overflow:visible;white-space:pre;wo=
rd-wrap:normal"><span style=3D"color:rgb(215,58,73)">int</span> <span style=
=3D"color:rgb(111,66,193)">main</span>() {</td></tr><tr><td style=3D"paddin=
g-right:10px;padding-left:10px;color:rgba(27,31,35,0.298039);font-family:SF=
Mono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;f=
ont-size:12px;line-height:20px;min-width:50px;text-align:right;vertical-ali=
gn:top;white-space:nowrap;width:50px"></td><td style=3D"padding-right:10px;=
padding-left:10px;line-height:20px;vertical-align:top;font-family:SFMono-Re=
gular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;font-siz=
e:12px;overflow:visible;white-space:pre;word-wrap:normal">    <span style=
=3D"color:rgb(215,58,73)">auto</span> glambda =3D []() { <span style=3D"col=
or:rgb(215,58,73)">return</span> <span style=3D"color:rgb(0,92,197)">incr</=
span>(); };</td></tr><tr><td style=3D"padding-right:10px;padding-left:10px;=
color:rgba(27,31,35,0.298039);font-family:SFMono-Regular,Consolas,&quot;Lib=
eration Mono&quot;,Menlo,Courier,monospace;font-size:12px;line-height:20px;=
min-width:50px;text-align:right;vertical-align:top;white-space:nowrap;width=
:50px"></td><td style=3D"padding-right:10px;padding-left:10px;line-height:2=
0px;vertical-align:top;font-family:SFMono-Regular,Consolas,&quot;Liberation=
 Mono&quot;,Menlo,Courier,monospace;font-size:12px;overflow:visible;white-s=
pace:pre;word-wrap:normal">    std::cout &lt;&lt; <span style=3D"color:rgb(=
0,92,197)">glambda</span>() &lt;&lt; std::endl</td></tr><tr><td style=3D"pa=
dding-right:10px;padding-left:10px;color:rgba(27,31,35,0.298039);font-famil=
y:SFMono-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospa=
ce;font-size:12px;line-height:20px;min-width:50px;text-align:right;vertical=
-align:top;white-space:nowrap;width:50px"></td><td style=3D"padding-right:1=
0px;padding-left:10px;line-height:20px;vertical-align:top;font-family:SFMon=
o-Regular,Consolas,&quot;Liberation Mono&quot;,Menlo,Courier,monospace;font=
-size:12px;overflow:visible;white-space:pre;word-wrap:normal">    <span sty=
le=3D"color:rgb(215,58,73)">return</span> <span style=3D"color:rgb(0,92,197=
)">0</span>;</td></tr><tr><td style=3D"padding-right:10px;padding-left:10px=
;color:rgba(27,31,35,0.298039);font-family:SFMono-Regular,Consolas,&quot;Li=
beration Mono&quot;,Menlo,Courier,monospace;font-size:12px;line-height:20px=
;min-width:50px;text-align:right;vertical-align:top;white-space:nowrap;widt=
h:50px"></td><td style=3D"padding-right:10px;padding-left:10px;line-height:=
20px;vertical-align:top;font-family:SFMono-Regular,Consolas,&quot;Liberatio=
n Mono&quot;,Menlo,Courier,monospace;font-size:12px;overflow:visible;white-=
space:pre;word-wrap:normal">}</td></tr></tbody></table></blockquote><div>=
=C2=A0</div>I thought about how to give a guarantee that a method is a pure=
, stateless mathematical function.<div>=C2=A0Ideally, this should work for =
both lambda expressions and normal methods.</div><div><br></div><div>My ide=
a was to introduce a lambda keyword for methods.</div><div>This keyword wou=
ld guarantee that the method does not have state.</div><div>And tell the Co=
mpiler to verify that or throw a compile-time error.</div><div><br></div><d=
iv>Rules for &quot;lambda&quot; methods would be:</div><div><ul><li>Variabl=
es:</li><ul><li>Only arguments</li><li>and Local Variables</li><li>and =C2=
=A0all constants</li></ul><li>Methods:</li><ul><li>Only functions that are =
&quot;lambda&quot; themselves must be used</li><li>except for assignments l=
ike=C2=A0</li><ul><li>a=3D2;</li><li>a+=3D1;</li><li>a++;</li></ul></ul><li=
>Pointer:</li><ul><li>Only unique pointers can be used=C2=A0</li><li>So Poi=
nter must be passed via move semantic</li></ul><li>References:</li><ul><li>=
Can not be used as that would allow another thread to alter the value durin=
g execution.</li><li>the exception are references to constants</li></ul><li=
>Objects:</li><ul><li>Basically, all the rules above apply</li><li>=C2=A0Th=
e object must be passed as unique pointer via move semantic</li><li>Only pu=
re functions of the object are accessible.</li><li>assignments are only all=
owed to local Objects</li><li>static classes=C2=A0can always be passed thei=
r=C2=A0variables and methods are treated as described above.</li><li>Consta=
nt objects are allowed.</li></ul></ul>This would allow to flag vast parts o=
f standard methods as lambda (e.g. operator_+ ...). Then one could ensure t=
hat at least a subpart of his program is pure functional and guaranteed not=
 to cause race conditions.=C2=A0<br><div><br></div></div><div><br></div><di=
v><br></div><div>Best Regards Jakob=C2=A0</div></div></blockquote><div><br>=
</div><div>Half of work is done by:</div><div>http://open-std.org/JTC1/SC22=
/WG21/docs/papers/2015/n4487.pdf</div><div>In most cases your code will be =
rejected but if you add some `if` you can avoid this as long non-const code=
 is conditionally executed.</div><div>Portably correct solution is adding n=
ew category of function that can call only `constexpr` functions, this coul=
d be done by attributes because we are only rejecting valid code.</div><div=
><br></div><div>This could be two attributes: `[[pure]]` and `[[weak_pure]]=
` (probably there was already similar proposal).</div><div>`[[pure]]` allow=
 only calling other pure functions (this is viral attribute, because all ot=
her function called need have it too)</div><div>`[[weak_pure]]` only check =
if this function call only `constexpr` functions (that in reality can be no=
t pure at run time).<br></div></div>

<p></p>

-- <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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/62df37ad-d150-4216-8385-8d88f8597718%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/62df37ad-d150-4216-8385-8d88f8597718=
%40isocpp.org</a>.<br />

------=_Part_1077_296318740.1544308426236--

------=_Part_1076_2038982117.1544308426235--

.